简体   繁体   中英

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]

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM