Ticket #9459: datetime-microseconds-py24.patch

File datetime-microseconds-py24.patch, 2.6 KB (added by guettli, 5 years ago)

Updated patch, new: sys.version_info[:2]

  • django/conf/global_settings.py

     
    346346# * Note that these format strings are different from the ones to display dates
    347347DATETIME_INPUT_FORMATS = (
    348348    '%Y-%m-%d %H:%M:%S',     # '2006-10-25 14:30:59'
     349    '%Y-%m-%d %H:%M:%S.%f',  # '2006-10-25 14:30:59.000200'
    349350    '%Y-%m-%d %H:%M',        # '2006-10-25 14:30'
    350351    '%Y-%m-%d',              # '2006-10-25'
    351352    '%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
     
    418419                return None
    419420            value = '%s %s' % tuple(value)
    420421        for format in self.input_formats or formats.get_format('DATETIME_INPUT_FORMATS'):
     422            if format.endswith('.%f') and sys.version_info[:2]<=(2,6):
     423                if not value.count('.')==1:
     424                    continue
     425                try:
     426                    value, usecs = value.rsplit('.', 1)
     427                    usecs = int(usecs)
     428                    return datetime.datetime(*time.strptime(value, format[:-3])[:6]+(usecs,))
     429                except ValueError:
     430                    continue
    421431            try:
    422432                return datetime.datetime(*time.strptime(value, format)[:6])
    423433            except ValueError:
  • tests/regressiontests/forms/fields.py

     
    323323        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59)))
    324324        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59, 200), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59, 200)))
    325325        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45), f.clean('2006-10-25 14:30:45'))
     326        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45, 200), f.clean('2006-10-25 14:30:45.000200'))
    326327        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('2006-10-25 14:30:00'))
    327328        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('2006-10-25 14:30'))
    328329        self.assertEqual(datetime.datetime(2006, 10, 25, 0, 0), f.clean('2006-10-25'))
Back to Top