mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #17134: Corrected Python 2.5 fallback code for parsing microseconds in time values. Thanks aaugustin and jcd.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17092 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -340,11 +340,13 @@ class BaseTemporalField(Field):
|
||||
return self.strptime(value, format)
|
||||
except ValueError:
|
||||
if format.endswith('.%f'):
|
||||
if value.count('.') != 1:
|
||||
# Compatibility with datetime in pythons < 2.6.
|
||||
# See: http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior
|
||||
if value.count('.') != format.count('.'):
|
||||
continue
|
||||
try:
|
||||
datetime_str, usecs_str = value.rsplit('.', 1)
|
||||
usecs = int(usecs_str)
|
||||
usecs = int(usecs_str[:6].ljust(6, '0'))
|
||||
dt = datetime.datetime.strptime(datetime_str, format[:-3])
|
||||
return dt.replace(microsecond=usecs)
|
||||
except ValueError:
|
||||
|
||||
Reference in New Issue
Block a user