Does pytz function above year 2038?

Asked by Chris Schimp

It seems that above the year 2038 pytz stops applying DST?

Test Code that I used:
from datetime import datetime, timedelta
from pytz import timezone
import pytz
import subprocess
from tabulate import tabulate
import os
import sys

for x in range(1,31):
    day = datetime(2038, 3, x)
    tz = timezone('America/Toronto')

    print(tz.utcoffset(day).total_seconds()/60/60)

Question information

Language:
English Edit question
Status:
Expired
For:
pytz Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Holger Joukl (jholg) said :
#2

Last week I posted a comment here that is gone now?! Is this due to the question having been expired in the meantime?

OK. Let's try again:

From a glance at the pytz source code (http://bazaar.launchpad.net/~stub/pytz/devel/view/head:/src/pytz/tzfile.py) my understanding is that it only takes the original or "old version" tzfile information into account, not the "Version 2" information.

The "old version" basically underlies 32bit restrictions i.e. the recorded dst switching times end in 2038. This means that dst can't be correctly applied >= 2038.

"Version 2" format gist:
Following the "old version" data are dst transition times and leap second times recorded as 8 byte values (as opposed to 4 bytes) plus a POSIX-TZ-environment-variable-style string with the switching rule to apply for times after the last recorded transition time.

(see e.g. http://man7.org/linux/man-pages/man5/tzfile.5.html for details)

Note that both the pytz-included timezone database files (!) as well as the system-provided timezone files on a reasonably modern Linux (ususally /usr/share/zoneinfo on Linux) actually contain the "Version 2" information, it is just not getting used.

I'm currently looking for a Python library that handles this correctly but there seems to be None, so far. The other obvious Python library candidate (dateutil) also doesn't evaluate the "Version 2" information.

Revision history for this message
Stuart Bishop (stub) said :
#3

Pytz as of 2015.6 only supports v1 format files. Dates beyond 2038 use the last defined timezone, rather than the 'best guess' rules provided in the v2 format files for far future dates.