Skip to content

Instantly share code, notes, and snippets.

@ahmedbilal
Created December 8, 2023 10:33
Show Gist options
  • Save ahmedbilal/93e0b846e41b57b24b84f4d538363953 to your computer and use it in GitHub Desktop.
Save ahmedbilal/93e0b846e41b57b24b84f4d538363953 to your computer and use it in GitHub Desktop.
Creating recurring dates from aware datetime results in imaginary time
from datetime import datetime
from zoneinfo import ZoneInfo
from dateutil import tz
from dateutil.rrule import rrule, SA, SU, DAILY
start_date = datetime(2023, 3, 4, 2, 10, tzinfo=ZoneInfo("America/New_York"))
for dt in rrule(freq=DAILY, count=10, byweekday=[SA, SU], dtstart=start_date):
print(dt, tz.datetime_exists(dt))
"""
Output
-------------------------------
2023-03-04 02:10:00-05:00 True
2023-03-05 02:10:00-05:00 True
2023-03-11 02:10:00-05:00 True
2023-03-12 02:10:00-05:00 False
2023-03-18 02:10:00-04:00 True
2023-03-19 02:10:00-04:00 True
2023-03-25 02:10:00-04:00 True
2023-03-26 02:10:00-04:00 True
2023-04-01 02:10:00-04:00 True
2023-04-02 02:10:00-04:00 True
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment