Ticket #4121: dateformat.py.2.diff
File dateformat.py.2.diff, 2.7 KB (added by , 18 years ago) |
---|
-
django/utils/dateformat.py
13 13 14 14 from django.utils.dates import MONTHS, MONTHS_3, MONTHS_AP, WEEKDAYS 15 15 from django.utils.tzinfo import LocalTimezone 16 from django.utils.translation import get text as _16 from django.utils.translation import get_date_formats, get_partial_date_formats, gettext as _ 17 17 from calendar import isleap, monthrange 18 18 import re, time 19 19 20 re_formatchars = re.compile(r'(?<!\\)([aAb BdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])')20 re_formatchars = re.compile(r'(?<!\\)([aAbcBdDfFgGhHiIjkKlLmMnNOPrsStTUwWxXyYzZ])') 21 21 re_escaped = re.compile(r'\\(.)') 22 22 23 23 class Formatter(object): … … 101 101 "Seconds; i.e. '00' to '59'" 102 102 return '%02d' % self.data.second 103 103 104 def X(self): 105 "Time, appropriate time representation. e.g. '8:00'" 106 (date_format, datetime_format, time_format) = get_date_formats() 107 return format(self.data, time_format) 108 104 109 class DateFormat(TimeFormat): 105 110 year_days = [None, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334] 106 111 … … 115 120 "Month, textual, 3 letters, lowercase; e.g. 'jan'" 116 121 return MONTHS_3[self.data.month] 117 122 123 def c(self): 124 "Datetime, appropriate date and time representation.; e.g. '2007-04-23 05:00'" 125 (date_format, datetime_format, time_format) = get_date_formats() 126 return format(self.data, datetime_format) 127 118 128 def d(self): 119 129 "Day of the month, 2 digits with leading zeros; i.e. '01' to '31'" 120 130 return '%02d' % self.data.day … … 138 148 "Day of the month without leading zeros; i.e. '1' to '31'" 139 149 return self.data.day 140 150 151 def k(self): 152 "Month day, appropriate month day representation. e.g. 'January 5'" 153 (year_month_format, month_day_format) = get_partial_date_formats() 154 return format(self.data, month_day_format) 155 156 def K(self): 157 "Year month, appropriate year month representation. e.g. '2007 January'" 158 (year_month_format, month_day_format) = get_partial_date_formats() 159 return format(self.data, year_month_format) 160 141 161 def l(self): 142 162 "Day of the week, textual, long; e.g. 'Friday'" 143 163 return WEEKDAYS[self.data.weekday()] … … 230 250 week_number -= 1 231 251 return week_number 232 252 253 def x(self): 254 "Date, appropriate date representation. e.g. '2007-04-23'" 255 (date_format, datetime_format, time_format) = get_date_formats() 256 return format(self.data, date_format) 257 233 258 def y(self): 234 259 "Year, 2 digits; e.g. '99'" 235 260 return str(self.data.year)[2:]