[ZCM] [ZC] 2056/ 8 Reject "strftime %d off by one"

Collector: Zope Bugs, Features, and Patches ... zope-coders-admin at zope.org
Sun Aug 27 09:00:25 EDT 2006


Issue #2056 Update (Reject) "strftime %d off by one"
 Status Rejected, Zope/bug medium
To followup, visit:
  http://www.zope.org/Collectors/Zope/2056

==============================================================
= Reject - Entry #8 by shh on Aug 27, 2006 9:00 am

 Status: Pending => Rejected

Right, thanks. Rejecting as not-a-bug then.

Jim, I suggest you use the all-numeric-arguments form of the DateTime constructor for your use-case.

________________________________________
= Comment - Entry #7 by tseaver on Aug 26, 2006 8:40 am

The docstring of the 'DateTime._parse_args' method has this:

  New in Zope 2.4:
  The DateTime constructor automatically detects and handles
  ISO8601 compliant dates (YYYY-MM-DDThh:ss:mmTZD).
  See http://www.w3.org/TR/NOTE-datetime for full specs.

If the string uses one of the ISO8601 formats (no embedded spaces,
leading 4 digit year, hyphen as date element separator), then it
is parsed as a GMT, unless it has the trailing zone offset.
________________________________________
= Comment - Entry #6 by shh on Aug 26, 2006 6:19 am

Not quite, let's try again with GMT-5:

 >>> d1 = DateTime('2006-03-30 00:00 GMT-5') 
 >>> d1.strftime('%Y-%m-%d %H:%M') 
 '2006-03-30 00:00' 
 >>> d1 = DateTime('2006-03-30 00:00 GMT+0') 
 >>> d1.strftime('%Y-%m-%d %H:%M') 
 '2006-03-29 19:00' 
 >>> d1 = DateTime('2006-03-30')  
 >>> d1.strftime('%Y-%m-%d %H:%M') 
 '2006-03-29 19:00' 
 >>>  

As you can see '2006-03-30' yields the same result as '2006-03-30 00:00 GMT+0'. 
Now, if only I could find where *that* is documented... ;-)

Interestingly enough, if you don't rely on string parsing the time-portion will be localtime:

 >>> d1 = DateTime(2006, 3, 30)
 >>> d1.strftime('%Y-%m-%d %H:%M')
 '2006-03-30 00:00'

What gives?
________________________________________
= Comment - Entry #5 by mrmaple on Aug 25, 2006 9:14 am

Timezone shouldn't matter it's off by one _day_ not one hour.
In my session below I tell it it's the 30th, and it comes back with the 29th of the month.

The timezone would have to be GMT-29  instead of (where I am) GMT-5

________________________________________
= Comment - Entry #4 by shh on Aug 25, 2006 5:16 am

FWIW, DateTime.strftime is documented to use the local timezone.

    def strftime(self, format):
        # Format the date/time using the *current timezone representation*.
        ...

________________________________________
= Comment - Entry #3 by shh on Aug 24, 2006 10:00 am

My tzimezone is GMT+2. I get these results:

 >>> d1 = DateTime('2006-03-30 00:00 GMT+2')
 >>> d1.strftime('%Y-%m-%d %H:%M')
 '2006-03-30 00:00'
 >>> d1 = DateTime('2006-03-30 00:00 GMT+0')
 >>> d1.strftime('%Y-%m-%d %H:%M')
 '2006-03-30 02:00'
 >>> d1 = DateTime('2006-03-30') 
 >>> d1.strftime('%Y-%m-%d %H:%M')
 '2006-03-30 02:00'
 >>> 

________________________________________
= Comment - Entry #2 by mrmaple on Mar 30, 2006 9:55 am

I actually tried my example in a shell, and it worked... but this doesn't:

>>> d1 = DateTime("2006-03-30")
>>> d1
DateTime('2006/03/30')
>>> d1.strftime("%m/%d/%Y")
'03/29/2006'
>>>
________________________________________
= Request - Entry #1 by Anonymous User on Mar 30, 2006 9:39 am

date = DateTime()
date.strftime("%m/%d/%Y")  
# prints the wrong date!

I've had to change all my code to:
  "%s/%s/%s" % (date.month(), date.day(), date.year())

This might affect tons of people in a very bad way.
==============================================================



More information about the Zope-Collector-Monitor mailing list