Ticket #9721: django.datetimefield.optional.time.component.diff
File django.datetimefield.optional.time.component.diff, 1.5 KB (added by , 16 years ago) |
---|
-
django/forms/fields.py
381 381 # components: date and time. 382 382 if len(value) != 2: 383 383 raise ValidationError(self.error_messages['invalid']) 384 value = '%s %s' % tuple(value) 384 # To support input formats consisting of a date component only. 385 if value[1] in EMPTY_VALUES: 386 value = value[0] 387 else: 388 value = '%s %s' % tuple(value) 385 389 for format in self.input_formats: 386 390 try: 387 391 return datetime.datetime(*time.strptime(value, format)[:6]) -
tests/regressiontests/forms/fields.py
601 601 ... 602 602 ValidationError: [u'Enter a valid date/time.'] 603 603 604 DateTimeField supports list input: 605 >>> f.clean(['2008-11-22', '14:30']) 606 datetime.datetime(2008, 11, 22, 14, 30) 607 >>> f.clean(['2008-11-22', '']) 608 datetime.datetime(2008, 11, 22, 0, 0) 609 >>> f.clean(['2008-11-22']) 610 Traceback (most recent call last): 611 ... 612 ValidationError: [u'Enter a valid date/time.'] 613 604 614 DateField accepts an optional input_formats parameter: 605 615 >>> f = DateTimeField(input_formats=['%Y %m %d %I:%M %p']) 606 616 >>> f.clean(datetime.date(2006, 10, 25))