Ticket #4121: dateformat.py.diff
File dateformat.py.diff, 2.8 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): … … 100 100 def s(self): 101 101 "Seconds; i.e. '00' to '59'" 102 102 return '%02d' % self.data.second 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) 103 108 104 109 class DateFormat(TimeFormat): 105 110 year_days = [None, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334] … … 114 119 def b(self): 115 120 "Month, textual, 3 letters, lowercase; e.g. 'jan'" 116 121 return MONTHS_3[self.data.month] 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) 117 127 118 128 def d(self): 119 129 "Day of the month, 2 digits with leading zeros; i.e. '01' to '31'" … … 137 147 def j(self): 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()] … … 237 257 def Y(self): 238 258 "Year, 4 digits; e.g. '1999'" 239 259 return self.data.year 260 261 def x(self): 262 "Date, appropriate date representation. e.g. '2007-04-23'" 263 (date_format, datetime_format, time_format) = get_date_formats() 264 return format(self.data, date_format) 240 265 241 266 def z(self): 242 267 "Day of the year; i.e. '0' to '365'"