Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python pytz: what happens if a country does away with DST?

OK, this is more a curiosity question, but how does pytz know all the daylight savings times (DST)? For example, that 'Europe/Copenhagen' time switches in March and October.

Or rather, what happens if a country decides to do away with DST? Will everyone have to get an updated version of Pytz? Is there someone "at pytz" keeping track of this? Is there a formal list somewhere?

like image 888
user984003 Avatar asked Nov 12 '12 16:11

user984003


People also ask

How does pytz handle daylight Savings?

Introduction. pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher. It also solves the issue of ambiguous times at the end of daylight saving time, which you can read more about in the Python Library Reference ( datetime.

How does Python handle daylight time?

daylight() Function. Time. daylight() function which returns a non zero integer value when Daylight Saving Time (DST) is defined, else it returns 0.

What is the function to offset the date for daylight saving in Python?

You should use datetime. datetime. utcnow(). astimezone(tz) -- This gets the time in UTC and then offsets it from UTC according to whatever rules apply in the timezone tz.

What does pytz timezone do?

The pytz module allows for date-time conversion and timezone calculations so that your Python applications can keep track of dates and times, while staying accurate to the timezone of a particular location.


2 Answers

PyTZ uses the Olson timezone database, and it updates regularly. PyTZ is not the only user; most POSIX systems use it too, including Linux and OS X.

Yes, new revisions of PyTZ are packaged whenever that database updates.

like image 196
Martijn Pieters Avatar answered Oct 01 '22 12:10

Martijn Pieters


From the "Latest Versions" section of the pytz documentation:

This package will be updated after releases of the Olson timezone database.

So the answers to your questions appear to be yes, an update will be released if the tz database is updated, and you will need to update your installation of pytz.

like image 21
David Alber Avatar answered Oct 01 '22 12:10

David Alber