diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index 1300e86..ab31c15 100644
a
|
b
|
TIME_INPUT_FORMATS = (
|
366 | 366 | # * Note that these format strings are different from the ones to display dates |
367 | 367 | DATETIME_INPUT_FORMATS = ( |
368 | 368 | '%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59' |
| 369 | '%Y-%m-%d %H:%M:%S.%f', # '2006-10-25 14:30:59.000200' |
369 | 370 | '%Y-%m-%d %H:%M', # '2006-10-25 14:30' |
370 | 371 | '%Y-%m-%d', # '2006-10-25' |
371 | 372 | '%m/%d/%Y %H:%M:%S', # '10/25/2006 14:30:59' |
| 373 | '%m/%d/%Y %H:%M:%S.%f', # '10/25/2006 14:30:59.000200' |
372 | 374 | '%m/%d/%Y %H:%M', # '10/25/2006 14:30' |
373 | 375 | '%m/%d/%Y', # '10/25/2006' |
374 | 376 | '%m/%d/%y %H:%M:%S', # '10/25/06 14:30:59' |
| 377 | '%m/%d/%y %H:%M:%S.%f', # '10/25/06 14:30:59.000200' |
375 | 378 | '%m/%d/%y %H:%M', # '10/25/06 14:30' |
376 | 379 | '%m/%d/%y', # '10/25/06' |
377 | 380 | ) |
diff --git a/django/forms/fields.py b/django/forms/fields.py
index a5ea81d..b15ae49 100644
a
|
b
|
class BaseTemporalField(Field):
|
338 | 338 | try: |
339 | 339 | return self.strptime(value, format) |
340 | 340 | except ValueError: |
341 | | continue |
| 341 | # This code is required to support versions of python that don't support %f for time conversion |
| 342 | if format.endswith('.%f'): |
| 343 | if not value.count('.')==1: |
| 344 | continue |
| 345 | try: |
| 346 | datetime_str, usecs_str = value.rsplit('.', 1) |
| 347 | usecs = int(usecs_str) |
| 348 | return datetime.datetime(*time.strptime(datetime_str, format[:-3])[:6]+(usecs,)) |
| 349 | except ValueError: |
| 350 | continue |
342 | 351 | raise ValidationError(self.error_messages['invalid']) |
343 | 352 | |
344 | 353 | def strptime(self, value, format): |
… |
… |
class DateTimeField(BaseTemporalField):
|
417 | 426 | return super(DateTimeField, self).to_python(value) |
418 | 427 | |
419 | 428 | def strptime(self, value, format): |
420 | | return datetime.datetime(*time.strptime(value, format)[:6]) |
| 429 | return datetime.datetime.strptime(value, format) |
421 | 430 | |
422 | 431 | class RegexField(CharField): |
423 | 432 | def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs): |
diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
index 2303b4e..ad8d1d9 100644
a
|
b
|
class FieldsTests(TestCase):
|
379 | 379 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean(datetime.datetime(2006, 10, 25, 14, 30))) |
380 | 380 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59))) |
381 | 381 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59, 200), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59, 200))) |
| 382 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45, 200), f.clean('2006-10-25 14:30:45.000200')) |
382 | 383 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45), f.clean('2006-10-25 14:30:45')) |
383 | 384 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('2006-10-25 14:30:00')) |
384 | 385 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('2006-10-25 14:30')) |
385 | 386 | self.assertEqual(datetime.datetime(2006, 10, 25, 0, 0), f.clean('2006-10-25')) |
| 387 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45, 200), f.clean('10/25/2006 14:30:45.000200')) |
386 | 388 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45), f.clean('10/25/2006 14:30:45')) |
387 | 389 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/2006 14:30:00')) |
388 | 390 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/2006 14:30')) |
389 | 391 | self.assertEqual(datetime.datetime(2006, 10, 25, 0, 0), f.clean('10/25/2006')) |
| 392 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45, 200), f.clean('10/25/06 14:30:45.000200')) |
390 | 393 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45), f.clean('10/25/06 14:30:45')) |
391 | 394 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30:00')) |
392 | 395 | self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30')) |