#12377 closed defect (fixed)
iso8601 with high time resolution and no timezone leads strange timezone
| Reported by: | Jun Omae | Owned by: | Jun Omae |
|---|---|---|---|
| Priority: | low | Milestone: | 1.0.11 |
| Component: | general | Version: | |
| Severity: | minor | Keywords: | |
| Cc: | Branch: | ||
| Release Notes: |
Fix |
||
| API Changes: | |||
| Internal Changes: | |||
Description
I noticed strange behaviors in parse_date() while adding unit tests in [9b9c8a56e/jomae.git].
$ ~/venv/trac/1.0.10/bin/python Python 2.5.6 (r256:88840, Oct 21 2014, 22:26:35) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from trac.util.datefmt import parse_date, utc >>> parse_date('2016-01-02T12:34:56.987654', utc) datetime.datetime(2016, 1, 2, 12, 34, 56, 987654, tzinfo=<FixedOffset "UTC" 0:00:00>) >>> parse_date('2016-01-02T12:34:56.9876543', utc) datetime.datetime(2016, 1, 2, 12, 34, 56, 987650, tzinfo=<FixedOffset "None43:None" 19:00:00>) >>> parse_date('2016-01-02T12:34:56.98765432', utc) datetime.datetime(2016, 1, 2, 12, 34, 56, 987654, tzinfo=<FixedOffset "None32:None" 8:00:00>) >>> parse_date('2016-01-02T12:34:56.987654321', utc) datetime.datetime(2016, 1, 2, 12, 34, 56, 987650, tzinfo=<FixedOffset "None43:21" 19:21:00>) >>> parse_date('2016-01-02T12:34:56.9876543210', utc) datetime.datetime(2016, 1, 2, 12, 34, 56, 987654, tzinfo=<FixedOffset "None32:10" 8:10:00>) >>> parse_date('2016-01-02T12:34:56.98765432109', utc) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "~/venv/trac/1.0.10/lib/python2.5/site-packages/trac/util/datefmt.py", line 615, in parse_date raise TracError(msg, _('Invalid Date')) trac.core.TracError: "2016-01-02T12:34:56.98765432109" is an invalid date, or the date format is not known. Try "MM/dd/YY" or "YYYY-MM-DD" instead.
Attachments (0)
Change History (8)
comment:1 by , 10 years ago
comment:3 by , 10 years ago
Just something I spotted looking at [63b75491/jomae.git]: (\d\d):?(\d\d)? will also allow \d\d\d\d, which I think shouldn't be valid offset either. Perhaps use (\d\d)(?::(\d\d))? instead.
comment:4 by , 10 years ago
I think ISO 8601 allows +hhmm in timezone offset. See wikipedia:ISO_8601#Time_zone_designators and time-numoffset definition in rfc:3339#appendix-A.
comment:5 by , 10 years ago
OK, and of course only now I see the corresponding examples in the tests you added, please ignore my botched review ;-)
comment:6 by , 10 years ago
Yeah. Thanks for the looking! Ah, re pattern for iso8601 could be simple a bit.
( # timezone
Z # Z
- | (?:([-+])(\d\d):?(\d\d)?) # +hh:mm, -hh:mm, +hh, -hh
+ | ([-+])(\d\d):?(\d\d)? # ±hh:mm, ±hhmm, ±hh
)?
comment:7 by , 10 years ago
| Milestone: | next-stable-1.0.x → 1.0.11 |
|---|---|
| Owner: | set to |
| Status: | new → assigned |
comment:8 by , 10 years ago
| Release Notes: | modified (diff) |
|---|---|
| Resolution: | → fixed |
| Status: | assigned → closed |



Other issues: