[Zope] Help with DateTime.earliestTime()

Dieter Maurer dieter at handshake.de
Sun Aug 26 14:19:33 EDT 2007


Eric Thomas wrote at 2007-8-25 07:18 -0500:
>I've been having a site problem that I've tracked down to DateTime.  Simply
>enough, the code snippets below both try to add 31 days to the first day in
>October.  I'm expecting this to result in the first day of November.
>
>Good Example:
>
>>>> from DateTime import DateTime
>>>> start=DateTime('2005/10/01 01:00:00 GMT-5')
>>>> print start
>2005/10/01 01:00:00 GMT-5
>>>> earlyStart=start.earliestTime()
>>>> print earlyStart
>2005/10/01
>>>> print earlyStart+31
>2005/11/01
>
>Bad Example:  (Here's the problem)
>
>>>> from DateTime import DateTime
>>>> start=DateTime('2005/10/01 01:00:00 US/Central')
>>>> print start
>2005/10/01 01:00:00 US/Central
>>>> earlyStart=start.earliestTime()
>>>> print earlyStart
>2005/10/01
>>>> print earlyStart+31
>2005/10/31 23:00:00 US/Central
>
>I've confirmed this occurs with several of the US/ timezones (US/Pacific,
>US/Alaska, etc)

This looks like a daytime saving problem:

  With daytime saving, the clock often is put back for an hour
  at the last samday in october....

The "DateTime" implementation could avoid this
*if* the arithmetic would only accept
"int" (then it would be very likely that you only want to modify
the day but not hours, minutes and seconds). But the arithmetic
accepts "float" and that necessitates some surprises with
time discontinuities (such as daytime saving switches).



>
>Can anyone help me figure out why the resulting date is coming up 1 hour
>short of the expected 2005/11/01 ?
>
>Thanks!
>
>Eric
><div>I&#39;ve been having a site problem that I&#39;ve tracked down to DateTime.&nbsp; Simply enough, the code snippets below both try to add 31 days to the first day in October.&nbsp; I&#39;m expecting this to result in the first day of November.
></div>
><div>&nbsp;</div>
><div>Good Example:</div>
><div>
><p>&gt;&gt;&gt; from DateTime import DateTime<br>&gt;&gt;&gt; start=DateTime(&#39;2005/10/01 01:00:00 GMT-5&#39;)<br>&gt;&gt;&gt; print start<br>2005/10/01 01:00:00 GMT-5<br>&gt;&gt;&gt; earlyStart=start.earliestTime()<br>
>&gt;&gt;&gt; print earlyStart<br>2005/10/01<br>&gt;&gt;&gt; print earlyStart+31<br>2005/11/01</p></div>
><div>
><p>Bad Example:&nbsp; (Here&#39;s the problem)</p>
><p>&gt;&gt;&gt; from DateTime import DateTime<br>&gt;&gt;&gt; start=DateTime(&#39;2005/10/01 01:00:00 US/Central&#39;)<br>&gt;&gt;&gt; print start<br>2005/10/01 01:00:00 US/Central<br>&gt;&gt;&gt; earlyStart=start.earliestTime
>()<br>&gt;&gt;&gt; print earlyStart<br>2005/10/01<br>&gt;&gt;&gt; print earlyStart+31<br>2005/10/31 23:00:00 US/Central</p>
><p>I&#39;ve confirmed this occurs with several of the US/ timezones (US/Pacific, US/Alaska, etc)</p>
><p>Can anyone help me figure out why the resulting date is coming up 1 hour short of the expected 2005/11/01 ?</p>
><p>Thanks!</p>
><p>Eric</p>
><p>&nbsp;</p>
><p>&nbsp;</p></div>

-- 
Dieter


More information about the Zope mailing list