Skip to content
Advertisement

Why does this code work on Linux but not on Windows?

I asked a previous question here, regarding flagging Daylight Saving Time hours. @MattMessersmith kindly and expertly answered my question, and his solution worked perfectly in Linux (Ubuntu), but not on either of my Windows machines (work and home).

My Windows machines are both running Anaconda with Python 3.6 and pytz 2018.4, if that helps.

When I run the code on Windows, I get the following error:

Traceback (most recent call last): 
File "<ipython-input-185-ed30519c4311>", line 1, in <module> 
  transition_times = [t.astimezone(tz) for t in transition_times] 
File "<ipython-input-185-ed30519c4311>", line 1, in <listcomp> 
  transition_times = [t.astimezone(tz) for t in transition_times] 
OSError: [Errno 22] Invalid argument

Here is the code that produces the error on my Windows machines:

from pytz import timezone

# Map transition times to year for some efficiency gain                                                                                                                                                     
tz = timezone('America/Denver')
transition_times = tz._utc_transition_times[1:]
transition_times = [t.astimezone(tz) for t in transition_times]

Advertisement

Answer

This is a bug: [Windows] datetime.fromtimestamp(t) when 0 <= t <= 86399 fails on Python 3.6.

Because some datetime object in tz._utc_transition_times[1:] is less than 1970-01-01 00:00:00.000.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement