summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2008-07-18 03:45:30 +0000
committerAdrian Holovaty <adrian@holovaty.com>2008-07-18 03:45:30 +0000
commitf6fafc02c8ba60b950bbe6be3b3ba729038dbb0a (patch)
treeb4e2e6a0e926ba43f584e4803660598168b0f48e
parentc4d0cfe1eeff3bfec364ba59d23aaff8be093267 (diff)
Improved LocalTimezone._isdst() to handle dates before approximately 1901-12-01 (the specific cutoff date is platform-specific). Refs #1443
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7945 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/utils/tzinfo.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/django/utils/tzinfo.py b/django/utils/tzinfo.py
index d8bdee390a..9352acd52a 100644
--- a/django/utils/tzinfo.py
+++ b/django/utils/tzinfo.py
@@ -60,9 +60,17 @@ class LocalTimezone(tzinfo):
tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
try:
stamp = time.mktime(tt)
- except OverflowError:
- # 32 bit systems can't handle dates after Jan 2038, so we fake it
- # in that case (since we only care about the DST flag here).
+ except (OverflowError, ValueError):
+ # 32 bit systems can't handle dates after Jan 2038, and certain
+ # systems can't handle dates before ~1901-12-01:
+ #
+ # >>> time.mktime((1900, 1, 13, 0, 0, 0, 0, 0, 0))
+ # OverflowError: mktime argument out of range
+ # >>> time.mktime((1850, 1, 13, 0, 0, 0, 0, 0, 0))
+ # ValueError: year out of range
+ #
+ # In this case, we fake the date, because we only care about the
+ # DST flag.
tt = (2037,) + tt[1:]
stamp = time.mktime(tt)
tt = time.localtime(stamp)