Ticket #4121: dateformat.py.diff

File dateformat.py.diff, 2.8 KB (added by Ciantic, 8 years ago)

Adds missing functionality for DateFormat and TimeFormat

  • django/utils/dateformat.py

     
    1313
    1414from django.utils.dates import MONTHS, MONTHS_3, MONTHS_AP, WEEKDAYS
    1515from django.utils.tzinfo import LocalTimezone
    16 from django.utils.translation import gettext as _
     16from django.utils.translation import get_date_formats, get_partial_date_formats, gettext as _
    1717from calendar import isleap, monthrange
    1818import re, time
    1919
    20 re_formatchars = re.compile(r'(?<!\\)([aAbBdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])')
     20re_formatchars = re.compile(r'(?<!\\)([aAbcBdDfFgGhHiIjkKlLmMnNOPrsStTUwWxXyYzZ])')
    2121re_escaped = re.compile(r'\\(.)')
    2222
    2323class Formatter(object):
     
    100100    def s(self):
    101101        "Seconds; i.e. '00' to '59'"
    102102        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)     
    103108
    104109class DateFormat(TimeFormat):
    105110    year_days = [None, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
     
    114119    def b(self):
    115120        "Month, textual, 3 letters, lowercase; e.g. 'jan'"
    116121        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)
    117127
    118128    def d(self):
    119129        "Day of the month, 2 digits with leading zeros; i.e. '01' to '31'"
     
    137147    def j(self):
    138148        "Day of the month without leading zeros; i.e. '1' to '31'"
    139149        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   
    141161    def l(self):
    142162        "Day of the week, textual, long; e.g. 'Friday'"
    143163        return WEEKDAYS[self.data.weekday()]
     
    237257    def Y(self):
    238258        "Year, 4 digits; e.g. '1999'"
    239259        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)       
    240265
    241266    def z(self):
    242267        "Day of the year; i.e. '0' to '365'"
Back to Top