Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DatetimeRange timestamp iteration #17

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/chronify/time_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from datetime import datetime, timedelta
from typing import Any, Union, Literal
from zoneinfo import ZoneInfo

import pandas as pd
from pydantic import (
Expand Down Expand Up @@ -191,7 +192,15 @@ def list_time_columns(self) -> list[str]:

def iter_timestamps(self) -> Generator[datetime, None, None]:
for i in range(self.length):
cur = adjust_timestamp_by_dst_offset(self.start + i * self.resolution, self.resolution)
if self.is_time_zone_naive():
cur = adjust_timestamp_by_dst_offset(
self.start + i * self.resolution, self.resolution
)
else:
tz = self.start.tzinfo
# always step in standard time
cur_utc = self.start.astimezone(ZoneInfo("UTC")) + i * self.resolution
cur = adjust_timestamp_by_dst_offset(cur_utc.astimezone(tz), self.resolution)
month = cur.month
day = cur.day
if not (
Expand Down