diff options
| author | Karen Tracey <kmtracey@gmail.com> | 2011-11-13 00:43:02 +0000 |
|---|---|---|
| committer | Karen Tracey <kmtracey@gmail.com> | 2011-11-13 00:43:02 +0000 |
| commit | 0db571b417ce9f9f10e30fae8513fbeaebd55fa7 (patch) | |
| tree | dfd36fa1ada6813d8e043c5fdf1a678c38ea23e2 /django/forms | |
| parent | b45099eefb9a46264bcb8811dff6013cd1d0f6d6 (diff) | |
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
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/fields.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index 45cc8185c0..4cd2911eaa 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -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: |
