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

Comparison between tz-naive and tz-aware datetime objects due to floor_hour timezone erasure #45

Closed
broad-well opened this issue Jun 15, 2024 · 2 comments
Labels

Comments

@broad-well
Copy link

broad-well commented Jun 15, 2024

I haven't had time to find the exact conditions that trigger the condition described in the title, but from a little digging in my debugger, I found the following behavior in date_utils.py:

>>> floor_hour(datetime.datetime(2022, 12, 22, 8, 10, tzinfo=datetime.timezone.utc))
datetime.datetime(2022, 12, 22, 8, 0)

This effectively erases the timezone information. In my case, the return value is then compared to a timezone-aware datetime value from my dataset, which produces an error.

@broad-well
Copy link
Author

def floor_day(d: datetime) -> datetime:
    """
    Round down to the start of the day
    """
    return d.min.replace(d.year, d.month, d.day, tzinfo=d.tzinfo) if has_time(d) else d

This appears to fix it on my end.

has2k1 added a commit that referenced this issue Jul 26, 2024
@has2k1 has2k1 closed this as completed in 5381c8c Jul 26, 2024
@has2k1 has2k1 added the bug label Jul 26, 2024
@has2k1
Copy link
Owner

has2k1 commented Jul 26, 2024

Thanks for solution. It indeed was an oversight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants