Ticket #9459: datetime-microseconds-py24.2.patch

File datetime-microseconds-py24.2.patch, 2.6 KB (added by dmclain, 14 years ago)

sackcloth and ashes for bringing the hammer. Applies cleanly and tests run under 2.6 and 2.5

  • django/conf/global_settings.py

    diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
    index 1ab9b49..8e45d8f 100644
    a b TIME_INPUT_FORMATS = (  
    358358# * Note that these format strings are different from the ones to display dates
    359359DATETIME_INPUT_FORMATS = (
    360360    '%Y-%m-%d %H:%M:%S',     # '2006-10-25 14:30:59'
     361    '%Y-%m-%d %H:%M:%S.%f',  # '2006-10-25 14:30:59.000200'
    361362    '%Y-%m-%d %H:%M',        # '2006-10-25 14:30'
    362363    '%Y-%m-%d',              # '2006-10-25'
    363364    '%m/%d/%Y %H:%M:%S',     # '10/25/2006 14:30:59'
  • django/forms/fields.py

    diff --git a/django/forms/fields.py b/django/forms/fields.py
    index a5ea81d..612abec 100644
    a b import copy  
    66import datetime
    77import os
    88import re
     9import sys
    910import time
    1011import urlparse
    1112import warnings
    class BaseTemporalField(Field):  
    335336        # If unicode, try to strptime against each input format.
    336337        if isinstance(value, unicode):
    337338            for format in self.input_formats:
     339                if format.endswith('.%f') and sys.version_info[:2]<=(2,6):
     340                    if not value.count('.')==1:
     341                        continue
     342                    try:
     343                        value, usecs = value.rsplit('.', 1)
     344                        usecs = int(usecs)
     345                        return datetime.datetime(*time.strptime(value, format[:-3])[:6]+(usecs,))
     346                    except ValueError:
     347                        continue
    338348                try:
    339349                    return self.strptime(value, format)
    340350                except ValueError:
  • tests/regressiontests/forms/tests/fields.py

    diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
    index 2303b4e..03ad5bb 100644
    a b class FieldsTests(TestCase):  
    387387        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/2006 14:30:00'))
    388388        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/2006 14:30'))
    389389        self.assertEqual(datetime.datetime(2006, 10, 25, 0, 0), f.clean('10/25/2006'))
     390        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45, 200), f.clean('2006-10-25 14:30:45.000200'))
    390391        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45), f.clean('10/25/06 14:30:45'))
    391392        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30:00'))
    392393        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30'))
Back to Top