Ticket #9459: datetime-microseconds-py25.patch

File datetime-microseconds-py25.patch, 2.7 KB (added by guettli, 5 years ago)
  • django/conf/global_settings.py

     
    350350# * Note that these format strings are different from the ones to display dates
    351351DATETIME_INPUT_FORMATS = (
    352352    '%Y-%m-%d %H:%M:%S',     # '2006-10-25 14:30:59'
     353    '%Y-%m-%d %H:%M:%S.%f',  # '2006-10-25 14:30:59.000200'
    353354    '%Y-%m-%d %H:%M',        # '2006-10-25 14:30'
    354355    '%Y-%m-%d',              # '2006-10-25'
    355356    '%m/%d/%Y %H:%M:%S',     # '10/25/2006 14:30:59'
  • django/forms/fields.py

     
    55import datetime
    66import os
    77import re
     8import sys
    89import time
    910import urlparse
    1011import warnings
     
    401402                raise ValidationError(self.error_messages['invalid'])
    402403            value = '%s %s' % tuple(value)
    403404        for format in self.input_formats or formats.get_format('DATETIME_INPUT_FORMATS'):
     405            if format.endswith('.%f') and sys.version_info<=(2,6) and value.count('.')==1:
     406                try:
     407                    value, usecs = value.rsplit('.', 1)
     408                    usecs = int(usecs)
     409                    return datetime.datetime(*time.strptime(value, format[:-3])[:6]+(usecs,))
     410                except ValueError:
     411                    continue
    404412            try:
    405                 return datetime.datetime(*time.strptime(value, format)[:6])
     413                return datetime.datetime.strptime(value, format)
    406414            except ValueError:
    407415                continue
    408416        raise ValidationError(self.error_messages['invalid'])
  • tests/regressiontests/forms/fields.py

     
    320320        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59)))
    321321        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59, 200), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59, 200)))
    322322        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45), f.clean('2006-10-25 14:30:45'))
     323        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45, 200), f.clean('2006-10-25 14:30:45.000200'))
    323324        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('2006-10-25 14:30:00'))
    324325        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('2006-10-25 14:30'))
    325326        self.assertEqual(datetime.datetime(2006, 10, 25, 0, 0), f.clean('2006-10-25'))
Back to Top