summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2005-05-10 20:58:18 +0000
committerArch Librarian <arch@canonical.com>2005-05-10 20:58:18 +0000
commit27f32d47b54627115b03cb1ff0fcaade9d7b06eb (patch)
treee27c276731ee7cfd5a27e53d60cfc49345db9037
parent41e2fa30ede57d21fcd4ad81962e3a4db623295f (diff)
downloadpytz-27f32d47b54627115b03cb1ff0fcaade9d7b06eb.tar.gz
All localtime -> UTC tests now pass
Author: zenzen Date: 2004-07-24 18:05:54 GMT All localtime -> UTC tests now pass
-rw-r--r--gen_tests.py24
-rw-r--r--gen_tzinfo.py11
-rw-r--r--src/pytz/tzinfo.py21
3 files changed, 25 insertions, 31 deletions
diff --git a/gen_tests.py b/gen_tests.py
index ce363a0..3c5236d 100644
--- a/gen_tests.py
+++ b/gen_tests.py
@@ -1,11 +1,11 @@
#!/usr/bin/env python
# -*- coding: ascii -*-
'''
-$Id: gen_tests.py,v 1.12 2004/07/23 23:24:44 zenzen Exp $
+$Id: gen_tests.py,v 1.13 2004/07/24 18:05:54 zenzen Exp $
'''
-__rcs_id__ = '$Id: gen_tests.py,v 1.12 2004/07/23 23:24:44 zenzen Exp $'
-__version__ = '$Revision: 1.12 $'[11:-2]
+__rcs_id__ = '$Id: gen_tests.py,v 1.13 2004/07/24 18:05:54 zenzen Exp $'
+__version__ = '$Revision: 1.13 $'[11:-2]
import os, os.path, popen2, re, sys
from gen_tzinfo import allzones
@@ -53,8 +53,6 @@ from datetime import tzinfo, timedelta, datetime
prev_is_dst = False
for idx in range(0, len(lines)):
line = lines[idx]
- #if '2002' not in line:
- # continue
m = re.match(
'^([^\s]+)\s+(.+\sUTC) \s+=\s+ (.+)\s([^\s]+) \s+isdst=(0|1)$',
line, re.X
@@ -79,15 +77,10 @@ from datetime import tzinfo, timedelta, datetime
# Urgh - utcoffset() and dst() have to be rounded to the nearest
# minute, so we need to break our tests to match this limitation
- real_offset = utc_dt - local_dt
+ real_offset = local_dt - utc_dt
secs = real_offset.seconds + real_offset.days*86400
fake_offset = timedelta(seconds=int((secs+30)/60)*60)
- if prev_dt is not None and prev_dt.second == 59:
- utc_dt = utc_dt + fake_offset - real_offset
- elif utc_dt.second in (0,59):
- local_dt = local_dt - fake_offset + real_offset
- else:
- utc_dt = utc_dt + fake_offset - real_offset
+ local_dt = utc_dt + fake_offset
# If the naive time on the previous line is greater than on this
# line, and we arn't seeing an end-of-dst transition, then
@@ -102,13 +95,6 @@ from datetime import tzinfo, timedelta, datetime
prev_is_dst = is_dst
prev_dt = local_dt
- # datetime resolution of 1 minute means the dst transition
- # might now be off by 30 seconds.
- # Make 'instant before' tests '30 seconds before' to cope :-(
- if utc_dt.second == 59 or local_dt.second == 59:
- utc_dt = utc_dt - timedelta(seconds=30)
- local_dt = local_dt - timedelta(seconds=30)
-
local_string = '%s %s' % (
local_dt.strftime('%a %b %d %H:%M:%S %Y'), tzname
)
diff --git a/gen_tzinfo.py b/gen_tzinfo.py
index a7f4d8c..fa98e1c 100644
--- a/gen_tzinfo.py
+++ b/gen_tzinfo.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
'''
-$Id: gen_tzinfo.py,v 1.18 2004/07/23 23:24:44 zenzen Exp $
+$Id: gen_tzinfo.py,v 1.19 2004/07/24 18:05:54 zenzen Exp $
'''
import sys, os, os.path, shutil
@@ -187,15 +187,12 @@ class DstGen(Gen):
tzname = inf[2]
# Round utcoffset and dst to the nearest minute or the
- # datetime library will complain
+ # datetime library will complain. Conversions to these timezones
+ # might be up to plus or minus 30 seconds out, but it is
+ # the best we can do.
real_utcoffset = utcoffset
utcoffset = int((utcoffset+30)/60)*60
dst = int((dst+30)/60)*60
- # And adjust the transition time to cope
- try:
- utc_tt = utc_tt + timedelta(seconds=real_utcoffset - utcoffset)
- except OverflowError:
- pass
utc_transition_times.append(utc_tt)
transition_info.append( (utcoffset, dst, tzname) )
diff --git a/src/pytz/tzinfo.py b/src/pytz/tzinfo.py
index be022b0..0f9690e 100644
--- a/src/pytz/tzinfo.py
+++ b/src/pytz/tzinfo.py
@@ -1,10 +1,8 @@
#!/usr/bin/env python
-'''
-$Id: tzinfo.py,v 1.4 2004/07/23 23:24:45 zenzen Exp $
-'''
+'''$Id: tzinfo.py,v 1.5 2004/07/24 18:05:55 zenzen Exp $'''
-__rcs_id__ = '$Id: tzinfo.py,v 1.4 2004/07/23 23:24:45 zenzen Exp $'
-__version__ = '$Revision: 1.4 $'[11:-2]
+__rcs_id__ = '$Id: tzinfo.py,v 1.5 2004/07/24 18:05:55 zenzen Exp $'
+__version__ = '$Revision: 1.5 $'[11:-2]
from datetime import datetime, timedelta, tzinfo
from bisect import bisect_right
@@ -57,6 +55,12 @@ class BaseTzInfo(tzinfo):
class StaticTzInfo(BaseTzInfo):
+ '''A timezone that has a constant offset from UTC
+
+ These timezones are rare, as most regions have changed their
+ offset from UTC at some point in their history
+
+ '''
def fromutc(self, dt):
'''See datetime.tzinfo.fromutc'''
return (dt + self._utcoffset).replace(tzinfo=self)
@@ -82,6 +86,13 @@ class StaticTzInfo(BaseTzInfo):
class DstTzInfo(BaseTzInfo):
+ '''A timezone that has a variable offset from UTC
+
+ The offset might change if daylight savings time comes into effect,
+ or at a point in history when the region decides to change their
+ timezone definition.
+
+ '''
# Overridden in subclass
_utc_transition_times = None # Sorted list of DST transition times in UTC
_transition_info = None # [(utcoffset, dstoffset, tzname)] corresponding