From 2f59e94a4150c84c8b4e387fd82f0509eadc4f4b Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 19 Aug 2012 21:47:41 +0200 Subject: 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. --- django/utils/dateparse.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'django/utils/dateparse.py') 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\d{4})-(?P\d{1,2})-(?P\d{1,2})$' ) -datetime_re = re.compile( - r'(?P\d{4})-(?P\d{1,2})-(?P\d{1,2})' - r'[T ](?P\d{1,2}):(?P\d{1,2})' +time_re = re.compile( + r'(?P\d{1,2}):(?P\d{1,2})' r'(?::(?P\d{1,2})(?:\.(?P\d{1,6})\d{0,6})?)?' - r'(?PZ|[+-]\d{1,2}:\d{1,2})?$' ) -time_re = re.compile( - r'(?P\d{1,2}):(?P\d{1,2})' +datetime_re = re.compile( + r'(?P\d{4})-(?P\d{1,2})-(?P\d{1,2})' + r'[T ](?P\d{1,2}):(?P\d{1,2})' r'(?::(?P\d{1,2})(?:\.(?P\d{1,6})\d{0,6})?)?' + r'(?PZ|[+-]\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) -- cgit v1.3