Skip to content

Commit

Permalink
clarify the optionality of "T" and "Z" in the ISO datetime format; ad…
Browse files Browse the repository at this point in the history
…d explicit tests
  • Loading branch information
r1chardj0n3s committed Dec 4, 2012
1 parent 2598e17 commit 84187ac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
9 changes: 5 additions & 4 deletions README.rst
Expand Up @@ -91,8 +91,7 @@ Format Specification
Most often a straight format-less ``{}`` will suffice where a more complex
format specification might have been used.

Most of `format()`'s `Format Specification Mini-Language`_ is supported with
some minor changes::
Most of `format()`'s `Format Specification Mini-Language`_ is supported:

[[fill]align][0][width][type]

Expand All @@ -105,7 +104,8 @@ The differences between `parse()` and `format()` are:
That is, the "#" format character is handled automatically by d, b, o
and x formats. For "d" any will be accepted, but for the others the correct
prefix must be present if at all.
- Similarly number sign is handled automatically.
- Numberic sign is handled automatically.
- The thousands separator is handled automatically if the "n" type is used.
- The types supported are a slightly different mix to the format() types. Some
format() types come directly over: "d", "n", "%", "f", "e", "b", "o" and "x".
In addition some regular expression character group types "D", "w", "W", "s"
Expand All @@ -132,7 +132,8 @@ Type Characters Matched Output
o Octal numbers int
x Hexadecimal numbers (lower and upper case) int
ti ISO 8601 format date/time datetime
e.g. 1972-01-20T10:21:36Z
e.g. 1972-01-20T10:21:36Z ("T" and "Z"
optional)
te RFC2822 e-mail format date/time datetime
e.g. Mon, 20 Jan 1972 10:21:36 +1000
tg Global (day/month) format date/time datetime
Expand Down
3 changes: 2 additions & 1 deletion parse.py
Expand Up @@ -132,7 +132,8 @@
o Octal numbers int
x Hexadecimal numbers (lower and upper case) int
ti ISO 8601 format date/time datetime
e.g. 1972-01-20T10:21:36Z
e.g. 1972-01-20T10:21:36Z ("T" and "Z"
optional)
te RFC2822 e-mail format date/time datetime
e.g. Mon, 20 Jan 1972 10:21:36 +1000
tg Global (day/month) format date/time datetime
Expand Down
15 changes: 12 additions & 3 deletions test_parse.py
Expand Up @@ -347,21 +347,30 @@ def n(fmt, s, e):
y('a {:ti} b', 'a 1997-07-16 b', datetime(1997, 7, 16))

# YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
y('a {:ti} b', 'a 1997-07-16T19:20 b', datetime(1997, 7, 16, 19, 20, 0))
y('a {:ti} b', 'a 1997-07-16 19:20 b',
datetime(1997, 7, 16, 19, 20, 0))
y('a {:ti} b', 'a 1997-07-16T19:20 b',
datetime(1997, 7, 16, 19, 20, 0))
y('a {:ti} b', 'a 1997-07-16T19:20Z b',
datetime(1997, 7, 16, 19, 20, tzinfo=utc))
y('a {:ti} b', 'a 1997-07-16T19:20+01:00 b',
datetime(1997, 7, 16, 19, 20, tzinfo=tz60))

# YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
y('a {:ti} b', 'a 1997-07-16T19:20:30 b', datetime(1997, 7, 16, 19, 20, 30))
y('a {:ti} b', 'a 1997-07-16 19:20:30 b',
datetime(1997, 7, 16, 19, 20, 30))
y('a {:ti} b', 'a 1997-07-16T19:20:30 b',
datetime(1997, 7, 16, 19, 20, 30))
y('a {:ti} b', 'a 1997-07-16T19:20:30Z b',
datetime(1997, 7, 16, 19, 20, 30, tzinfo=utc))
y('a {:ti} b', 'a 1997-07-16T19:20:30+01:00 b',
datetime(1997, 7, 16, 19, 20, 30, tzinfo=tz60))

# YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
y('a {:ti} b', 'a 1997-07-16T19:20:30.500000 b', datetime(1997, 7, 16, 19, 20, 30, 500000))
y('a {:ti} b', 'a 1997-07-16 19:20:30.500000 b',
datetime(1997, 7, 16, 19, 20, 30, 500000))
y('a {:ti} b', 'a 1997-07-16T19:20:30.500000 b',
datetime(1997, 7, 16, 19, 20, 30, 500000))
y('a {:ti} b', 'a 1997-07-16T19:20:30.5Z b',
datetime(1997, 7, 16, 19, 20, 30, 500000, tzinfo=utc))
y('a {:ti} b', 'a 1997-07-16T19:20:30.5+01:00 b',
Expand Down

0 comments on commit 84187ac

Please sign in to comment.