web/lib/django/utils/dateformat.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
equal deleted inserted replaced
28:b758351d191f 29:cc9b7e14412b
    17 from django.utils.dates import MONTHS, MONTHS_3, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR
    17 from django.utils.dates import MONTHS, MONTHS_3, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR
    18 from django.utils.tzinfo import LocalTimezone
    18 from django.utils.tzinfo import LocalTimezone
    19 from django.utils.translation import ugettext as _
    19 from django.utils.translation import ugettext as _
    20 from django.utils.encoding import force_unicode
    20 from django.utils.encoding import force_unicode
    21 
    21 
    22 re_formatchars = re.compile(r'(?<!\\)([aAbBdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])')
    22 re_formatchars = re.compile(r'(?<!\\)([aAbBcdDfFgGhHiIjlLmMnNOPrsStTUuwWyYzZ])')
    23 re_escaped = re.compile(r'\\(.)')
    23 re_escaped = re.compile(r'\\(.)')
    24 
    24 
    25 class Formatter(object):
    25 class Formatter(object):
    26     def format(self, formatstr):
    26     def format(self, formatstr):
    27         pieces = []
    27         pieces = []
   102 
   102 
   103     def s(self):
   103     def s(self):
   104         "Seconds; i.e. '00' to '59'"
   104         "Seconds; i.e. '00' to '59'"
   105         return u'%02d' % self.data.second
   105         return u'%02d' % self.data.second
   106 
   106 
       
   107     def u(self):
       
   108         "Microseconds"
       
   109         return self.data.microsecond
       
   110 
       
   111 
   107 class DateFormat(TimeFormat):
   112 class DateFormat(TimeFormat):
   108     year_days = [None, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
   113     year_days = [None, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
   109 
   114 
   110     def __init__(self, dt):
   115     def __init__(self, dt):
   111         # Accepts either a datetime or date object.
   116         # Accepts either a datetime or date object.
   115             self.timezone = LocalTimezone(dt)
   120             self.timezone = LocalTimezone(dt)
   116 
   121 
   117     def b(self):
   122     def b(self):
   118         "Month, textual, 3 letters, lowercase; e.g. 'jan'"
   123         "Month, textual, 3 letters, lowercase; e.g. 'jan'"
   119         return MONTHS_3[self.data.month]
   124         return MONTHS_3[self.data.month]
       
   125 
       
   126     def c(self):
       
   127         """
       
   128         ISO 8601 Format
       
   129         Example : '2008-01-02T10:30:00.000123'
       
   130         """
       
   131         return self.data.isoformat(' ')
   120 
   132 
   121     def d(self):
   133     def d(self):
   122         "Day of the month, 2 digits with leading zeros; i.e. '01' to '31'"
   134         "Day of the month, 2 digits with leading zeros; i.e. '01' to '31'"
   123         return u'%02d' % self.data.day
   135         return u'%02d' % self.data.day
   124 
   136