Edgewall Software
Modify

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#8662 closed enhancement (fixed)

format date in RFC 3339 subset (profile) of ISO 8601

Reported by: anatoly techtonik <techtonik@…> Owned by: techtonik@…
Priority: normal Milestone: 0.12
Component: rendering Version: 0.11-stable
Severity: normal Keywords: patch
Cc: martin@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Christian Boos)

Currently util.datefmt.format_datetime() is able to produce ISO 8601 compliant format given 'iso8601' as argument. The proposal is to increase interoperability by making datetime format compliant with RFC 3339 profile of ISO 8601.

That means that date will still be ISO 8601, but it will be additionally suitable for generating output that uses RFC 3339 based datetime, such as Atom.

See rfc:3339#section-5.6

  • trac/util/datefmt.py

     
    100100   
    101101    The formatting will be done using the given `format`, which consist
    102102    of conventional `strftime` keys. In addition the format can be 'iso8601'
    103     to specify the international date format.
     103    to specify the international date format (compliant with rfc3339).
    104104
    105105    `tzinfo` will default to the local timezone if left to `None`.
    106106    """
     
    125125    text = t.strftime(format)
    126126    if normalize_Z:
    127127        text = text.replace('+0000', 'Z')
     128        text = text[:-2] + ":" + text[-2:]
    128129    encoding = locale.getpreferredencoding() or sys.getdefaultencoding()
    129130    if sys.platform != 'win32' or sys.version_info[:2] > (2, 3):
    130131        encoding = locale.getlocale(locale.LC_TIME)[1] or encoding

Attachments (2)

rfc3339.diff (925 bytes ) - added by anatoly techtonik <techtonik@…> 15 years ago.
rfc3339.2.diff (958 bytes ) - added by anatoly techtonik <techtonik@…> 15 years ago.
second edition

Download all attachments as: .zip

Change History (18)

by anatoly techtonik <techtonik@…>, 15 years ago

Attachment: rfc3339.diff added

comment:1 by Christian Boos, 15 years ago

Description: modified (diff)
Milestone: 0.12

Why not, but please fix the patch (only do this substitution if test[-1] != 'Z').

comment:2 by Christian Boos, 15 years ago

s/test/text/

by anatoly techtonik <techtonik@…>, 15 years ago

Attachment: rfc3339.2.diff added

second edition

comment:3 by anatoly techtonik <techtonik@…>, 15 years ago

Thanks for review. New version is attached. Will it be included in 0.11 series as well?

comment:4 by anatoly techtonik <techtonik@…>, 15 years ago

Keywords: patch added

comment:5 by Remy Blank, 15 years ago

Owner: set to Remy Blank

I'll integrate this.

comment:6 by Remy Blank, 15 years ago

Resolution: fixed
Status: newclosed

Patch applied in [8708], along with a simplification of the logic in format_datetime().

comment:7 by Remy Blank, 15 years ago

Owner: changed from Remy Blank to techtonik@…

comment:8 by Martin Scharrer <martin@…>, 15 years ago

Cc: martin@… added
Resolution: fixed
Status: closedreopened

This doesn't work with my Trac installations (0.11.6 and 0.12dev). The colon is always missing. Trac itself apparently takes it as optional, but e.g. the Google Sitemap service rejects the generated dates as invalid because of the missing colon. This affects the th:GoogleSitemapPlugin.

Here the results of my manual test, the automatic tests look fine to me but apparently doesn't catch this.

Python 2.5.2 (r252:60911, Jan 20 2010, 23:14:04) 
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.util.datefmt import format_datetime
>>> print format_datetime(0, 'iso8601')
1970-01-01T01:00:00+0100
>>> print format_datetime(0, 'iso8601 ')
1970-01-01T01:00:00+0100
>>> print format_datetime(0, 'iso8601 time')
01:00:00+0100

comment:9 by Martin Scharrer <martin@…>, 15 years ago

Owner: changed from techtonik@… to Remy Blank
Status: reopenednew

comment:10 by Remy Blank, 15 years ago

Weird, this must be a locale issue. Here, I get the following:

Python 2.6.4 (r264, Mar  5 2010, 00:59:14)
[GCC 4.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.util.datefmt import format_datetime
>>> print format_datetime(0, 'iso8601')
1970-01-01T01:00:00+01:00
>>> print format_datetime(0, 'iso8601 ')
1970-01-01T01:00:00+01:00
>>> print format_datetime(0, 'iso8601 time')
01:00:00+01:00

What do you get for the following:

>>> from trac.util.datefmt import to_datetime, localtz
>>> to_datetime(0).astimezone(localtz).strftime('%Y-%m-%dT%H:%M:%S%z')
'1970-01-01T01:00:00+0100'
>>> localtz
<LocalTimezone "CET" 1:00:00 "CEST" 2:00:00>

Also, what's the output of "locale" on your system?

comment:11 by Martin Scharrer <martin@…>, 15 years ago

Thanks for responding so quickly.

Here the requested output:

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.util.datefmt import to_datetime, localtz
>>> to_datetime(0).astimezone(localtz).strftime('%Y-%m-%dT%H:%M:%S%z')
'1970-01-01T00:00:00+0000'
>>> localtz
<LocalTimezone "GMT" 0:00:00 "IST" 1:00:00>
>>> 
>>> 

And my "locale":

LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=

comment:12 by Martin Scharrer <martin@…>, 15 years ago

Sorry, the data above are from my home Trac 0.12 installation. This seems to work, I get the colon. My first post was from my workstation with Trac 0.11.6

On my server with Trac 0.11.6 I get the original missing colon and the follow output:

Python 2.5.2 (r252:60911, Jan 20 2010, 23:14:04) 
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.util.datefmt import to_datetime, localtz
>>> to_datetime(0).astimezone(localtz).strftime('%Y-%m-%dT%H:%M:%S%z')
'1970-01-01T01:00:00+0100'
>>> localtz
<trac.util.datefmt.LocalTimezone object at 0x20075b90>

The locale settings are identical to my last post.

in reply to:  12 comment:13 by Remy Blank, 15 years ago

Resolution: fixed
Status: newclosed

Replying to Martin Scharrer <martin@…>:

Sorry, the data above are from my home Trac 0.12 installation. This seems to work, I get the colon. My first post was from my workstation with Trac 0.11.6

Heh, mid-air collision, and I was going to ask exactly that.

On my server with Trac 0.11.6 I get the original missing colon and the follow output:

Yes, this is to be expected, as this ticket has been fixed on trunk only. We don't have any plans to backport the fix to 0.11-stable, so I'm closing this again.

comment:14 by Remy Blank, 15 years ago

Owner: changed from Remy Blank to techtonik@…

comment:15 by Martin Scharrer <martin@…>, 15 years ago

Funny, I must have confused the versions then, because I actually checked if the above code was included in the Trac installations I used before reopening the ticket. I was under the (wrong) impression it had been backported.

Yeah, this happens if someone has three computer with three different tracs … Sorry for the noise!

comment:16 by anatoly techtonik <techtonik@…>, 15 years ago

np. Datetime handling is a major Python weakness.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain techtonik@….
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from techtonik@… to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.