#18728: dateparse datetime regex should accept colon in TZ offset
-------------------------------------+-------------------------------------
Reporter: thaxter | Owner: aaugustin
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Resolution:
Keywords: datetime dateparse | Triage Stage:
iso8601 | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by thaxter):
* easy: 0 => 1
Comment:
The patch needs an enhancement. When tzinfo is converted to an offset, it
uses string subscripting to a string that is now variable/different
length. This patch removes the colon and changes the subscript in addition
to updating the regex. This prevents a bug that would occur when the
minutes in the offset are not zero.
{{{
21c21
< r'(?P<tzinfo>Z|[+-]\d{1,2}:\d{1,2})?$'
---
> r'(?P<tzinfo>Z|[+-]\d{1,2}:?\d{1,2})?$'
79c79,80
< offset = 60 * int(tzinfo[1:3]) + int(tzinfo[4:6])
---
> tzinfo = re.sub(r':','',tzinfo)
> offset = 60 * int(tzinfo[1:3]) + int(tzinfo[3:5])
}}}
This demo code shows that it works.
{{{
from django.utils.dateparse import parse_datetime
foo = '2012-08-06T01:00:00+01:02'
bar = '2012-08-06T01:00:00+0102'
print parse_datetime(foo).isoformat()
print parse_datetime(bar).isoformat()
}}}
Output:
{{{
2012-08-06T01:00:00+01:02
2012-08-06T01:00:00+01:02
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/18728#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.