Ticket #7262: microsecond.patch

File microsecond.patch, 2.9 KB (added by zegor, 16 years ago)

The full patch with unittest and doc

  • django/utils/dateformat.py

    old new  
    1818from calendar import isleap, monthrange
    1919import re, time
    2020
    21 re_formatchars = re.compile(r'(?<!\\)([aAbBdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])')
     21re_formatchars = re.compile(r'(?<!\\)([aAbBcdDfFgGhHiIjlLmMnNOPrsStTUuwWyYzZ])')
    2222re_escaped = re.compile(r'\\(.)')
    2323
    2424class Formatter(object):
     
    103103        "Seconds; i.e. '00' to '59'"
    104104        return u'%02d' % self.data.second
    105105
     106    def u(self):
     107        "Microseconds"
     108        return self.data.microsecond
     109
     110
    106111class DateFormat(TimeFormat):
    107112    year_days = [None, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
    108113
     
    117122        "Month, textual, 3 letters, lowercase; e.g. 'jan'"
    118123        return MONTHS_3[self.data.month]
    119124
     125    def c(self):
     126        """
     127        ISO 8601 Format
     128        Example : '2008-01-02 10:30:00.000123'
     129        """
     130        return self.data.isoformat(' ')
     131
    120132    def d(self):
    121133        "Day of the month, 2 digits with leading zeros; i.e. '01' to '31'"
    122134        return u'%02d' % self.data.day
  • docs/templates.txt

    old new  
    916916    A                 ``'AM'`` or ``'PM'``.                     ``'AM'``
    917917    b                 Month, textual, 3 letters, lowercase.     ``'jan'``
    918918    B                 Not implemented.
     919    c                 ISO 8601 Format                           ``2008-01-02 10:30:00.000123``
    919920    d                 Day of the month, 2 digits with           ``'01'`` to ``'31'``
    920921                      leading zeros.
    921922    D                 Day of the week, textual, 3 letters.      ``'Fri'``
     
    952953                      month, 2 characters.
    953954    t                 Number of days in the given month.        ``28`` to ``31``
    954955    T                 Time zone of this machine.                ``'EST'``, ``'MDT'``
     956    u                 Microseconds                              ``0`` to ``999999``
    955957    U                 Not implemented.
    956958    w                 Day of the week, digits without           ``'0'`` (Sunday) to ``'6'`` (Saturday)
    957959                      leading zeros.
  • tests/regressiontests/dateformat/tests.py

    old new  
    55u'p.m.'
    66>>> format(my_birthday, 'A')
    77u'PM'
     8>>> format(timestamp, 'c')
     9u'2008-05-19 11:45:23.123456'
    810>>> format(my_birthday, 'd')
    911u'08'
    1012>>> format(my_birthday, 'j')
     
    3941True
    4042>>> no_tz or format(my_birthday, 'U') == '300531600'
    4143True
     44>>> format(timestamp, 'u')
     45u'123456'
    4246>>> format(my_birthday, 'w')
    4347u'0'
    4448>>> format(my_birthday, 'W')
     
    8892summertime = datetime.datetime(2005, 10, 30, 1, 00)
    8993wintertime = datetime.datetime(2005, 10, 30, 4, 00)
    9094the_future = datetime.datetime(2100, 10, 25, 0, 00)
     95timestamp = datetime.datetime(2008, 5, 19, 11, 45, 23, 123456)
Back to Top