0

I am reading on SO that the Python standard library does not define any time-zones.

Also, from the Python 2.7 datetime docs:

Note that no concrete tzinfo classes are supplied by the datetime module.

However, calling utcnow() generates the current time in UTC. Furthermore, Python can also provide the current local time with now(). I am assuming that this is only possible if Python "knows" the local time-to-UTC offset (in order to return the correct values).

But doesn't that mean that Python is timezone aware? What am I missing?

Community
  • 1
  • 1
edsioufi
  • 8,297
  • 3
  • 36
  • 42

1 Answers1

2

Your OS provides the current timezone, as well as UTC time.

The OS does not, however, provide other timezone info, such as when DST switches take place. In other words, you can get the current time in the UTC timezone, but not accurately calculate local time across the year, as the offset to UTC changes with the summertime and wintertime switches.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Okay I see. But I can't help but asking myself why doesn't the OS provide the additional timezone info? Are there any historical reasons for this? I don't understand why the OS is trusted to give the current time but not enough to give DSTs? – edsioufi Aug 16 '13 at 15:46
  • 1
    There are historical reasons, yes. No standards, the C API doesn't provide anything more than UTC vs local time (and the current and alternative offsets, if dst is active and a (very) ambiguous 3-letter code for the timezone). – Martijn Pieters Aug 16 '13 at 15:48