Ticket #9459: ticket9459.patch

File ticket9459.patch, 4.4 KB (added by Michael Thornhill, 13 years ago)
  • django/conf/global_settings.py

    diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
    index 1300e86..ab31c15 100644
    a b TIME_INPUT_FORMATS = (  
    366366# * Note that these format strings are different from the ones to display dates
    367367DATETIME_INPUT_FORMATS = (
    368368    '%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'
    369370    '%Y-%m-%d %H:%M',        # '2006-10-25 14:30'
    370371    '%Y-%m-%d',              # '2006-10-25'
    371372    '%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'
    372374    '%m/%d/%Y %H:%M',        # '10/25/2006 14:30'
    373375    '%m/%d/%Y',              # '10/25/2006'
    374376    '%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'
    375378    '%m/%d/%y %H:%M',        # '10/25/06 14:30'
    376379    '%m/%d/%y',              # '10/25/06'
    377380)
  • django/forms/fields.py

    diff --git a/django/forms/fields.py b/django/forms/fields.py
    index a5ea81d..b15ae49 100644
    a b class BaseTemporalField(Field):  
    338338                try:
    339339                    return self.strptime(value, format)
    340340                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
    342351        raise ValidationError(self.error_messages['invalid'])
    343352
    344353    def strptime(self, value, format):
    class DateTimeField(BaseTemporalField):  
    417426        return super(DateTimeField, self).to_python(value)
    418427
    419428    def strptime(self, value, format):
    420         return datetime.datetime(*time.strptime(value, format)[:6])
     429        return datetime.datetime.strptime(value, format)
    421430
    422431class RegexField(CharField):
    423432    def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs):
  • tests/regressiontests/forms/tests/fields.py

    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):  
    379379        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean(datetime.datetime(2006, 10, 25, 14, 30)))
    380380        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59)))
    381381        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'))
    382383        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45), f.clean('2006-10-25 14:30:45'))
    383384        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('2006-10-25 14:30:00'))
    384385        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('2006-10-25 14:30'))
    385386        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'))
    386388        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45), f.clean('10/25/2006 14:30:45'))
    387389        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/2006 14:30:00'))
    388390        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/2006 14:30'))
    389391        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'))
    390393        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45), f.clean('10/25/06 14:30:45'))
    391394        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30:00'))
    392395        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30'))
Back to Top