Ticket #9762: rfc2822.2.2.diff
File rfc2822.2.2.diff, 2.9 KB (added by , 15 years ago) |
---|
-
django/utils/dateformat.py
14 14 import re 15 15 import time 16 16 import calendar 17 from email.utils import formatdate 17 18 from django.utils.dates import MONTHS, MONTHS_3, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR 18 19 from django.utils.tzinfo import LocalTimezone 19 20 from django.utils.translation import ugettext as _ … … 172 173 173 174 def r(self): 174 175 "RFC 2822 formatted date; e.g. 'Thu, 21 Dec 2000 16:01:07 +0200'" 175 return self.format('D, j M Y H:i:s O') 176 # solution taken from http://bugs.python.org/issue665194 until 177 # Python addresses this feature 178 timestamp = time.mktime(self.data.timetuple()) 179 return formatdate(timestamp, True) 176 180 177 181 def S(self): 178 182 "English ordinal suffix for the day of the month, 2 characters; i.e. 'st', 'nd', 'rd' or 'th'" -
tests/regressiontests/dateformat/tests.py
1 2 from django.utils import dateformat, translation3 1 from unittest import TestCase 4 2 import datetime, os, time 3 from django.conf import settings 4 from django.utils import dateformat, translation 5 5 6 6 class DateFormatTests(TestCase): 7 7 def setUp(self): 8 8 self.old_TZ = os.environ.get('TZ') 9 9 os.environ['TZ'] = 'Europe/Copenhagen' 10 10 translation.activate('en-us') 11 settings.LANGUAGE_CODE = 'en' 11 12 12 13 try: 13 14 # Check if a timezone has been set … … 82 83 83 84 if self.tz_tests: 84 85 self.assertEquals(dateformat.format(my_birthday, 'O'), u'+0100') 85 self.assertEquals(dateformat.format(my_birthday, 'r'), u'Sun, 8 Jul 1979 22:00:00 +0100')86 self.assertEquals(dateformat.format(my_birthday, 'r'), u'Sun, 08 Jul 1979 22:00:00 +0100') 86 87 self.assertEquals(dateformat.format(my_birthday, 'T'), u'CET') 87 88 self.assertEquals(dateformat.format(my_birthday, 'U'), u'300315600') 88 89 self.assertEquals(dateformat.format(my_birthday, 'Z'), u'3600') … … 90 91 self.assertEquals(dateformat.format(summertime, 'O'), u'+0200') 91 92 self.assertEquals(dateformat.format(wintertime, 'I'), u'0') 92 93 self.assertEquals(dateformat.format(wintertime, 'O'), u'+0100') 94 95 def test_rfc2822_trans(self): 96 settings.LANGUAGE_CODE='es' 97 translation.activate('es') 98 # Even though the language is now Spanish the RFC 2822 date string 99 # should not be translated. Sun, not "dom" 100 not_my_birthday = datetime.datetime(1979, 7, 8, 22, 00) 101 102 if self.tz_tests: 103 self.assertEquals( dateformat.format(not_my_birthday, 'r'), u'Sun, 08 Jul 1979 22:00:00 +0100')