[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.131,1.132 test_datetime.py,1.90,1.91
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Tue, 31 Dec 2002 20:12:04 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv7366
Modified Files:
datetime.py test_datetime.py
Log Message:
The failure of the last-second addition to the timezone coversion test is
understood now: it can't work. Added comments explaining why (it's "the
usual"-- unrepresentable hours in local time --but in a slightly different
guise).
Added an optimization to astimezone(). This will pay off more in the C
implementation (which is already optimized to work with offsets as C
ints internally, instead of with timedelta objects; this will let it
replace a datetimetz comparison call with a couple of int operations; in
the Python implementation it trades away a datetimetz comparison call
for a couple of timedelta operations).
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.131
retrieving revision 1.132
diff -C2 -d -r1.131 -r1.132
*** datetime.py 31 Dec 2002 15:56:31 -0000 1.131
--- datetime.py 1 Jan 2003 04:12:00 -0000 1.132
***************
*** 1639,1643 ****
return other
! other += otoff - myoff
# If tz is a fixed-offset class, we're done, but we can't know
# whether it is. If it's a DST-aware class, and we're not near a
--- 1639,1644 ----
return other
! total_added_to_other = otoff - myoff
! other += total_added_to_other
# If tz is a fixed-offset class, we're done, but we can't know
# whether it is. If it's a DST-aware class, and we're not near a
***************
*** 1650,1654 ****
self._inconsistent_utcoffset_error()
if newoff != otoff:
! other += newoff - otoff
otoff = other.utcoffset()
if otoff is None:
--- 1651,1657 ----
self._inconsistent_utcoffset_error()
if newoff != otoff:
! delta = newoff - otoff
! total_added_to_other += delta
! other += delta
otoff = other.utcoffset()
if otoff is None:
***************
*** 1663,1677 ****
if altoff is None:
self._inconsistent_utcoffset_error()
! # Are alt and other really the same time? alt == other iff
# alt - altoff == other - otoff, iff
# (other - _HOUR) - altoff = other - otoff, iff
# otoff - altoff == _HOUR
diff = otoff - altoff
if diff == _HOUR:
return alt # use the local time that makes sense
# There's still a problem with the unspellable (in local time)
! # hour after DST ends.
! if self == other:
return other
# Else there's no way to spell self in zone other.tz.
--- 1666,1693 ----
if altoff is None:
self._inconsistent_utcoffset_error()
! # Are alt and other really the same time? They are iff
# alt - altoff == other - otoff, iff
# (other - _HOUR) - altoff = other - otoff, iff
# otoff - altoff == _HOUR
+ # Note that the Python comparison "alt == other" would return false,
+ # though, because they have same tzinfo member, and utcoffset() is
+ # ignored when comparing times w/ the same tzinfo.
diff = otoff - altoff
+
+ # Enable the assert if you're dubious; it's expensive.
+ ##assert ((diff == _HOUR) ==
+ ## (alt.replace(tzinfo=None) - alt.utcoffset() ==
+ ## other.replace(tzinfo=None) - other.utcoffset()))
if diff == _HOUR:
return alt # use the local time that makes sense
# There's still a problem with the unspellable (in local time)
! # hour after DST ends. other's local time now is
! # self + total_added_to_other, so self == other iff
! # self - myoff = other - otoff, iff
! # self - myoff = self + total_added_to_other - otoff, iff
! # total_added_to_other == otoff - myoff
! ##assert (self == other) == (total_added_to_other == otoff - myoff)
! if total_added_to_other == otoff - myoff:
return other
# Else there's no way to spell self in zone other.tz.
Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_datetime.py,v
retrieving revision 1.90
retrieving revision 1.91
diff -C2 -d -r1.90 -r1.91
*** test_datetime.py 31 Dec 2002 15:32:12 -0000 1.90
--- test_datetime.py 1 Jan 2003 04:12:00 -0000 1.91
***************
*** 2606,2610 ****
dstoff = datetimetz(2002, 10, 27, 2)
-
# Check a time that's inside DST.
def checkinside(self, dt, tz, utc, dston, dstoff):
--- 2606,2609 ----
***************
*** 2706,2712 ****
self.convert_between_tz_and_utc(Eastern, Pacific)
self.convert_between_tz_and_utc(Pacific, Eastern)
! # XXX These fail!
! #self.convert_between_tz_and_utc(Eastern, Central)
! #self.convert_between_tz_and_utc(Central, Eastern)
--- 2705,2720 ----
self.convert_between_tz_and_utc(Eastern, Pacific)
self.convert_between_tz_and_utc(Pacific, Eastern)
! # OTOH, these fail! Don't enable them. The difficulty is that
! # the edge case tests assume that every hour is representable in
! # the "utc" class. This is always true for a fixed-offset tzinfo
! # class (lke utc_real and utc_fake), but not for Eastern or Central.
! # For these adjacent DST-aware time zones, the range of time offsets
! # tested ends up creating hours in the one that aren't representable
! # in the other. For the same reason, we would see failures in the
! # Eastern vs Pacific tests too if we added 3*HOUR to the list of
! # offset deltas in convert_between_tz_and_utc().
! #
! # self.convert_between_tz_and_utc(Eastern, Central) # can't work
! # self.convert_between_tz_and_utc(Central, Eastern) # can't work