DateTime.strftime bug

Bug #142784 reported by Steve Alexander
This bug report is a duplicate of:  Bug #143543: DateTime.strftime %Z value is blank. Edit Remove
4
Affects Status Importance Assigned to Milestone
DateTime
Incomplete
Medium
Lennart Regebro

Bug Description

strftime doesn't seem to respect the timezone

>>> DateTime.DateTime('Wed, 19 Nov 2003 18:32:07 -0200').strftime('%Y-%m-%d %H:%M %Z')
'2003-11-19 18:32 GMT'

There's regex code (that I wrote way back when...) that actually does this properly in the DateTime.strftime code. For some reason, it no longer works as it should do. Some other change must have broken it.

Tags: bug zope
Revision history for this message
Lennart Regebro (regebro-gmail) wrote :

The regexp '(^\|[^%])%z' makes no sense, and (^|[^%])%z' seems to work better.

I would be interested in knowing why the much simpler "format.replace('%Z', '%0+05d' % (diff/36))" isn't used. That at least doesn't take 20 minutes to debug by carefully analyzing regexps and seems to do what is needed, which is to replace %Z with the timezone... ;)

Revision history for this message
Lennart Regebro (regebro-gmail) wrote :

Status: Pending => Accepted

 Supporters added: regebro

OK, the regexp is to support %%Z. Got it! :)
However, the strftime seems to be there to get the time in the LOCAL timezone (according to the comments) and then

  return strftime(format, safelocaltime(self))

seems sufficient, which would also fix the bug with fractiona timzones that the current implementation has.

Revision history for this message
Lennart Regebro (regebro-gmail) wrote :

Status: Accepted => Resolved

DateTime.strftime() now does the same as time.strftime, that is, it returns the string according to the format converted to the local timezone.

Checked in both in Trunk and 2.7 branch and will therefore appear in 2.8 betas and later, and 2.7.4 (if one is made).

Revision history for this message
Paul Winkler (slinkp) wrote :

"%Z" no longer does anything, on 2.9 or trunk:

>>> import DateTime
>>> d = DateTime.DateTime().toZone('US/Pacific')
>>> d.strftime('%H:%M %Z')
'18:15 '

See also https://bugs.launchpad.net/zope2/+bug/215991 ... people (well, at least two of us) find the implicit conversion to local zone very suprising.

Changed in zope2:
status: Fix Released → Incomplete
affects: zope2 → datetime
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.