Ticket #12139: datetime_time_fractional_seconds.patch

File datetime_time_fractional_seconds.patch, 1.9 KB (added by mattbennett, 14 years ago)
  • django/forms/fields.py

    ### Eclipse Workspace Patch 1.0
    #P djangotrunk
     
    311311        raise ValidationError(self.error_messages['invalid'])
    312312
    313313DEFAULT_TIME_INPUT_FORMATS = (
     314    '%H:%M:%S.%f',  # '14:30:59.123456'
    314315    '%H:%M:%S',     # '14:30:59'
    315316    '%H:%M',        # '14:30'
    316317)
     
    337338            return value
    338339        for format in self.input_formats:
    339340            try:
    340                 return datetime.time(*time.strptime(value, format)[3:6])
     341                # split usecs, because they are not recognized by strptime.
     342                if '.' in value:
     343                    usecs = int(value.split('.')[-1])
     344                else:
     345                    usecs = 0
     346                return datetime.time(*time.strptime(value, format)[3:6],**{'microsecond':usecs})
    341347            except ValueError:
    342348                continue
    343349        raise ValidationError(self.error_messages['invalid'])
    344350
    345351DEFAULT_DATETIME_INPUT_FORMATS = (
     352    '%Y-%m-%d %H:%M:%S.%f',  # '2006-10-25 14:30:59.123456'
    346353    '%Y-%m-%d %H:%M:%S',     # '2006-10-25 14:30:59'
    347354    '%Y-%m-%d %H:%M',        # '2006-10-25 14:30'
    348355    '%Y-%m-%d',              # '2006-10-25'
     
    384391            value = '%s %s' % tuple(value)
    385392        for format in self.input_formats:
    386393            try:
    387                 return datetime.datetime(*time.strptime(value, format)[:6])
     394                # split usecs, because they are not recognized by strptime.
     395                if '.' in value:
     396                    usecs = int(value.split('.')[-1])
     397                else:
     398                    usecs = 0
     399                return datetime.datetime(*time.strptime(value, format)[:6],**{'microsecond':usecs})
    388400            except ValueError:
    389401                continue
    390402        raise ValidationError(self.error_messages['invalid'])
Back to Top