diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-08-19 21:47:41 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-08-19 21:47:41 +0200 |
| commit | 2f59e94a4150c84c8b4e387fd82f0509eadc4f4b (patch) | |
| tree | 2fcf3e98e31f6afe47c3c01fb2d77fc029b20a9a /django/utils | |
| parent | a43ecc04445a02982cb9c52357db25066b197c37 (diff) | |
Fixed #18728 -- Made colon optional in tzinfo
Made two-digit hours and minutes mandatory in tzinfo (the code used
to crash if a one-digit representation was provided).
Added standalone tests for django.utils.dateparse.
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/dateparse.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/django/utils/dateparse.py b/django/utils/dateparse.py index a693dcbb68..b4bd559a66 100644 --- a/django/utils/dateparse.py +++ b/django/utils/dateparse.py @@ -15,16 +15,16 @@ date_re = re.compile( r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})$' ) -datetime_re = re.compile( - r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})' - r'[T ](?P<hour>\d{1,2}):(?P<minute>\d{1,2})' +time_re = re.compile( + r'(?P<hour>\d{1,2}):(?P<minute>\d{1,2})' r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?' - r'(?P<tzinfo>Z|[+-]\d{1,2}:\d{1,2})?$' ) -time_re = re.compile( - r'(?P<hour>\d{1,2}):(?P<minute>\d{1,2})' +datetime_re = re.compile( + r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})' + r'[T ](?P<hour>\d{1,2}):(?P<minute>\d{1,2})' r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?' + r'(?P<tzinfo>Z|[+-]\d{2}:?\d{2})?$' ) def parse_date(value): @@ -73,7 +73,7 @@ def parse_datetime(value): if tzinfo == 'Z': tzinfo = utc elif tzinfo is not None: - offset = 60 * int(tzinfo[1:3]) + int(tzinfo[4:6]) + offset = 60 * int(tzinfo[1:3]) + int(tzinfo[-2:]) if tzinfo[0] == '-': offset = -offset tzinfo = FixedOffset(offset) |
