Ticket #9762: rfc2822.diff

File rfc2822.diff, 1.6 KB (added by kgrandis, 15 years ago)

corrected rfc2822 implementation and added tests

  • django/utils/dateformat.py

     
    1717from django.utils.encoding import force_unicode
    1818from calendar import isleap, monthrange
    1919import re, time
     20from email.utils import formatdate
    2021
    2122re_formatchars = re.compile(r'(?<!\\)([aAbBdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])')
    2223re_escaped = re.compile(r'\\(.)')
     
    170171        return u"%+03d%02d" % (seconds // 3600, (seconds // 60) % 60)
    171172
    172173    def r(self):
    173         "RFC 2822 formatted date; e.g. 'Thu, 21 Dec 2000 16:01:07 +0200'"
    174         return self.format('D, j M Y H:i:s O')
     174        "RFC 2822 formatted date; e.g. 'Thu, 21 Dec 2000 16:01:07 +0200'"       
     175        # solution taken from http://bugs.python.org/issue665194 until
     176        # Python addresses implements this feature
     177        timestamp = time.mktime(self.data.timetuple())
     178        return formatdate(timestamp)
    175179
    176180    def S(self):
    177181        "English ordinal suffix for the day of the month, 2 characters; i.e. 'st', 'nd', 'rd' or 'th'"
  • tests/regressiontests/dateformat/tests.py

     
    6969
    7070>>> format(the_future, r'Y')
    7171u'2100'
     72
     73>>> from django.conf import settings
     74>>> settings.LANGUAGE_CODE='es'
     75>>> translation.activate('es')
     76>>> no_tz or format(my_birthday, 'r') == 'Sun, 8 Jul 1979 22:00:00 +0100'
     77True
    7278"""
    7379
    7480from django.utils import dateformat, translation
Back to Top