[Python-checkins] python/nondist/sandbox/datetime US.py,1.8,1.9
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Fri, 27 Dec 2002 11:27:39 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv5785
Modified Files:
US.py
Log Message:
In the doctest, fleshed out the traps when DST begins.
Index: US.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/US.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** US.py 27 Dec 2002 06:36:52 -0000 1.8
--- US.py 27 Dec 2002 19:27:37 -0000 1.9
***************
*** 42,46 ****
# of 2:MM:SS on that day doesn't make sense. We arbitrarily decide it
# intends DST then, making it a redundant spelling of 1:MM:SS standard
! # on that day.
dstoff = timedelta(hours=1)
--- 42,48 ----
# of 2:MM:SS on that day doesn't make sense. We arbitrarily decide it
# intends DST then, making it a redundant spelling of 1:MM:SS standard
! # on that day. A consequence of the redundant spelling is that
! # this timezone -> UTC -> this timezone can't always be an identity on
! # this end of the scale.
dstoff = timedelta(hours=1)
***************
*** 123,127 ****
Sun Apr 7 01:59:59 2002
! Right when DST starts.
>>> after = before + timedelta(seconds=1)
>>> printstuff(after)
--- 125,129 ----
Sun Apr 7 01:59:59 2002
! Right when DST starts -- although this doesn't work very well.
>>> after = before + timedelta(seconds=1)
>>> printstuff(after)
***************
*** 155,158 ****
--- 157,186 ----
0:59:59
+ Converting 'after' to UTC and back again isn't an identity, because, as
+ above, 2 is taken as being in DST, a synonym for 1 in standard time:
+
+ >>> printstuff(after.astimezone(utc).astimezone(Eastern)) # 1:00 standard
+ 2002-04-07 01:00:00-05:00
+ EST
+ (2002, 4, 7, 1, 0, 0, 6, 97, 0)
+ Sun Apr 7 01:00:00 2002
+
+ To get the start of DST in a robust way, we have to give the "naive clock"
+ time of 3:
+
+ >>> after = after.replace(hour=3)
+ >>> printstuff(after)
+ 2002-04-07 03:00:00-04:00
+ EDT
+ (2002, 4, 7, 3, 0, 0, 6, 97, 1)
+ Sun Apr 7 03:00:00 2002
+ >>> printstuff(after.astimezone(utc).astimezone(Eastern)) # now an identity
+ 2002-04-07 03:00:00-04:00
+ EDT
+ (2002, 4, 7, 3, 0, 0, 6, 97, 1)
+ Sun Apr 7 03:00:00 2002
+ >>> print after.astimezone(utc) - before.astimezone(utc)
+ 0:00:01
+
Now right before DST ends.
>>> before = datetimetz(2002, 10, 27, 1, 59, 59, tzinfo=Eastern)
***************
*** 183,187 ****
One more glitch: that one-hour gap contains times that can't be represented
! in Eastern. Here's one of them:
>>> phantom = before.astimezone(utc) + timedelta(seconds=1)
--- 211,216 ----
One more glitch: that one-hour gap contains times that can't be represented
! in Eastern (all times of the form 6:MM:SS UTC on this day). Here's one of
! them:
>>> phantom = before.astimezone(utc) + timedelta(seconds=1)
***************
*** 203,207 ****
We get *something*, of course, but converting it back to UTC isn't an
identity (not because of a bug in Eastern, but because this particular
! UTC time simply has no spelling in Eastern).
>>> printstuff(paradox.astimezone(utc))
--- 232,238 ----
We get *something*, of course, but converting it back to UTC isn't an
identity (not because of a bug in Eastern, but because this particular
! UTC time simply has no spelling in Eastern: 6:MM:SS UTC would be
! 1:MM:SS in EST or 2:MM:SS in EDT, but Eastern takes 1:MM:SS as being
! daylight and 2:MM:SS as being standard on this day):
>>> printstuff(paradox.astimezone(utc))