josiahcarlson / parse-crontab

Parse and use crontab schedules in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AmbiguousTimeError during DST changeover

camrdale opened this issue · comments

I started getting this error after 1am today, which is during the daylight savings time changeover:

next_alarm = CronTab(alarm.crontab).next(now=now, default_utc=False)
  File /lib/crontab/_crontab.py", line 438, in next
    delay += tz.utcoffset(now)
  File "/python27/python27_lib/versions/third_party/pytz-2017.2/pytz/tzinfo.py", line 408, in utcoffset
    dt = self.localize(dt, is_dst)
  File "/python27/python27_lib/versions/third_party/pytz-2017.2/pytz/tzinfo.py", line 349, in localize
    raise AmbiguousTimeError(dt)
AmbiguousTimeError: 2018-11-04 01:00:48.901902

The code I am using is roughly this:

timezone = pytz.timezone("America/Los_Angeles")
now = pytz.utc.localize(datetime.datetime.utcnow()).astimezone(timezone)
next_alarm = CronTab("30 8 * * MON-FRI").next(now=now, default_utc=False)

Sorry, this is the first time I'm seeing this. Have been pretty involved with some other work. I imagine the problem fixed itself after 2AM, no?

In any case, I've got a spec on my side that tells me what I should be seeing (when I implemented the timezone stuff), but I'm not sure why I didn't go with a solution that seems obvious right now. Either way, this shouldn't be an issue another fall.

This should be fixed in 0.22.3, just released. Let me know if you have any more problems.