#8662 closed enhancement (fixed)
format date in RFC 3339 subset (profile) of ISO 8601
Reported by: | Owned by: | ||
---|---|---|---|
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 )
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.
-
trac/util/datefmt.py
100 100 101 101 The formatting will be done using the given `format`, which consist 102 102 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). 104 104 105 105 `tzinfo` will default to the local timezone if left to `None`. 106 106 """ … … 125 125 text = t.strftime(format) 126 126 if normalize_Z: 127 127 text = text.replace('+0000', 'Z') 128 text = text[:-2] + ":" + text[-2:] 128 129 encoding = locale.getpreferredencoding() or sys.getdefaultencoding() 129 130 if sys.platform != 'win32' or sys.version_info[:2] > (2, 3): 130 131 encoding = locale.getlocale(locale.LC_TIME)[1] or encoding
Attachments (2)
Change History (18)
by , 15 years ago
Attachment: | rfc3339.diff added |
---|
comment:1 by , 15 years ago
Description: | modified (diff) |
---|---|
Milestone: | → 0.12 |
comment:3 by , 15 years ago
Thanks for review. New version is attached. Will it be included in 0.11 series as well?
comment:4 by , 15 years ago
Keywords: | patch added |
---|
comment:6 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch applied in [8708], along with a simplification of the logic in format_datetime()
.
comment:7 by , 15 years ago
Owner: | changed from | to
---|
comment:8 by , 15 years ago
Cc: | added |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
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 , 15 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
comment:10 by , 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 , 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=
follow-up: 13 comment:12 by , 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.
comment:13 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
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 , 15 years ago
Owner: | changed from | to
---|
comment:15 by , 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!
Why not, but please fix the patch (only do this substitution if
test[-1] != 'Z'
).