[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.138,1.139 doc.txt,1.77,1.78 test_datetime.py,1.92,1.93
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Thu, 02 Jan 2003 11:25:29 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv5288
Modified Files:
datetime.py doc.txt test_datetime.py
Log Message:
astimezone() internals: if utcoffset() returns a duration, complain if
dst() returns None (instead of treating that as 0).
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.138
retrieving revision 1.139
diff -C2 -d -r1.138 -r1.139
*** datetime.py 2 Jan 2003 17:47:06 -0000 1.138
--- datetime.py 2 Jan 2003 19:25:27 -0000 1.139
***************
*** 1645,1649 ****
otdst = other.dst()
if otdst is None:
! otdst = 0
total_added_to_other = otoff - otdst - myoff
if total_added_to_other:
--- 1645,1650 ----
otdst = other.dst()
if otdst is None:
! raise ValueError("astimezone(): utcoffset() returned a duration "
! "but dst() returned None")
total_added_to_other = otoff - otdst - myoff
if total_added_to_other:
***************
*** 1666,1669 ****
--- 1667,1672 ----
other += delta
otoff = other.utcoffset()
+ if otoff is None:
+ self._inconsistent_utcoffset_error()
##assert (other == self) == (otoff - myoff == total_added_to_other)
if otoff - myoff == total_added_to_other:
Index: doc.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/doc.txt,v
retrieving revision 1.77
retrieving revision 1.78
diff -C2 -d -r1.77 -r1.78
*** doc.txt 1 Jan 2003 20:52:11 -0000 1.77
--- doc.txt 2 Jan 2003 19:25:27 -0000 1.78
***************
*** 792,805 ****
return CONSTANT + self.dst(dt) # daylight-aware class
! - tzname(self, dt)
! Return the timezone name corresponding to the datetime represented
! by dt, as a string. Nothing about string names is defined by the
! datetime module, and there's no requirement that it mean anything
! in particular. For example, "GMT", "UTC", "-500", "-5:00", "EDT",
! "US/Eastern", "America/New York" are all valid replies. Return
! None if a string name isn't known. Note that this is a method
! rather than a fixed string primarily because some tzinfo objects
! will wish to return different names depending on the specific value
! of dt passed, especially if the tzinfo class is accounting for DST.
- dst(self, dt)
--- 792,797 ----
return CONSTANT + self.dst(dt) # daylight-aware class
! If utcoffset() does not return None, dst() should not return None
! either.
- dst(self, dt)
***************
*** 826,829 ****
--- 818,832 ----
this, but cannot detect violations; it's the programmer's
responsibility to ensure it.
+
+ - tzname(self, dt)
+ Return the timezone name corresponding to the datetime represented
+ by dt, as a string. Nothing about string names is defined by the
+ datetime module, and there's no requirement that it mean anything
+ in particular. For example, "GMT", "UTC", "-500", "-5:00", "EDT",
+ "US/Eastern", "America/New York" are all valid replies. Return
+ None if a string name isn't known. Note that this is a method
+ rather than a fixed string primarily because some tzinfo objects
+ will wish to return different names depending on the specific value
+ of dt passed, especially if the tzinfo class is accounting for DST.
These methods are called by a datetimetz or timetz object, in response to
Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_datetime.py,v
retrieving revision 1.92
retrieving revision 1.93
diff -C2 -d -r1.92 -r1.93
*** test_datetime.py 1 Jan 2003 20:52:12 -0000 1.92
--- test_datetime.py 2 Jan 2003 19:25:27 -0000 1.93
***************
*** 2606,2609 ****
--- 2606,2611 ----
dstoff = datetimetz(2002, 10, 27, 2)
+ theclass = datetimetz
+
# Check a time that's inside DST.
def checkinside(self, dt, tz, utc, dston, dstoff):
***************
*** 2743,2746 ****
--- 2745,2763 ----
got = sixutc.astimezone(Eastern).astimezone(None)
self.assertEqual(expected, got)
+
+ def test_bogus_dst(self):
+ class ok(tzinfo):
+ def utcoffset(self, dt): return HOUR
+ def dst(self, dt): return HOUR
+
+ now = self.theclass.now().replace(tzinfo=utc_real)
+ # Doesn't blow up.
+ now.astimezone(ok())
+
+ # Does blow up.
+ class notok(ok):
+ def dst(self, dt): return None
+ self.assertRaises(ValueError, now.astimezone, notok())
+
def test_suite():