Skip to content

Instantly share code, notes, and snippets.

@michelbl
Last active May 7, 2024 13:07
Show Gist options
  • Save michelbl/e1052bbb517357c796cb5fccaba8ba04 to your computer and use it in GitHub Desktop.
Save michelbl/e1052bbb517357c796cb5fccaba8ba04 to your computer and use it in GitHub Desktop.
A list of surprises, using datetimes with the python ecosystem
from datetime import UTC
from zoneinfo import ZoneInfo
TZ_PARIS = ZoneInfo("Europe/Paris")
TZ_UTC = UTC
# datetime equality is bugged
datetime(2023, 10, 29, 2, 30, fold=0, tzinfo=TZ_PARIS) == datetime(2023, 10, 29, 2, 30, fold=1, tzinfo=TZ_PARIS) # True
datetime(2023, 10, 29, 2, 30, fold=0, tzinfo=TZ_PARIS).timestamp() == datetime(2023, 10, 29, 2, 30, fold=1, tzinfo=TZ_PARIS).timestamp() # False
# good literature:
# https://blog.ganssle.io/articles/2018/02/aware-datetime-arithmetic.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment