Ticket #9459: datetimefield-microseconds.diff
File datetimefield-microseconds.diff, 1.6 KB (added by , 16 years ago) |
---|
-
tests/regressiontests/forms/fields.py
560 560 datetime.datetime(2006, 10, 25, 14, 30, 59, 200) 561 561 >>> f.clean('2006-10-25 14:30:45') 562 562 datetime.datetime(2006, 10, 25, 14, 30, 45) 563 >>> f.clean('2006-10-25 14:30:45.123') 564 datetime.datetime(2006, 10, 25, 14, 30, 45, 123) 563 565 >>> f.clean('2006-10-25 14:30:00') 564 566 datetime.datetime(2006, 10, 25, 14, 30) 565 567 >>> f.clean('2006-10-25 14:30') -
django/forms/fields.py
382 382 if len(value) != 2: 383 383 raise ValidationError(self.error_messages['invalid']) 384 384 value = '%s %s' % tuple(value) 385 386 # To support DateTimeField in HiddenInput (incl. microseconds) 387 # YYYY-MM-DD HH:MM:SS.sss 388 if '.' in value: 389 try: 390 value, usecs = value.split('.') 391 usecs = int(usecs) 392 except ValueError: 393 raise ValidationError(self.error_messages['invalid']) 394 else: 395 usecs = 0 396 385 397 for format in self.input_formats: 386 398 try: 387 return datetime.datetime(*time.strptime(value, format)[:6] )399 return datetime.datetime(*time.strptime(value, format)[:6], **{'microsecond': usecs}) 388 400 except ValueError: 389 401 continue 390 402 raise ValidationError(self.error_messages['invalid'])