Ticket #9762: rfc2822.3.diff
File rfc2822.3.diff, 3.2 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 self.original_language = settings.LANGUAGE_CODE 12 settings.LANGUAGE_CODE = 'en' 11 13 12 14 try: 13 15 # Check if a timezone has been set … … 18 20 self.tz_tests = False 19 21 20 22 def tearDown(self): 23 settings.LANGUAGE_CODE = self.original_language 21 24 if self.old_TZ is None: 22 25 del os.environ['TZ'] 23 26 else: … … 82 85 83 86 if self.tz_tests: 84 87 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')88 self.assertEquals(dateformat.format(my_birthday, 'r'), u'Sun, 08 Jul 1979 22:00:00 +0100') 86 89 self.assertEquals(dateformat.format(my_birthday, 'T'), u'CET') 87 90 self.assertEquals(dateformat.format(my_birthday, 'U'), u'300315600') 88 91 self.assertEquals(dateformat.format(my_birthday, 'Z'), u'3600') … … 90 93 self.assertEquals(dateformat.format(summertime, 'O'), u'+0200') 91 94 self.assertEquals(dateformat.format(wintertime, 'I'), u'0') 92 95 self.assertEquals(dateformat.format(wintertime, 'O'), u'+0100') 96 97 def test_rfc2822_trans(self): 98 settings.LANGUAGE_CODE='es' 99 translation.activate('es') 100 # Even though the language is now Spanish the RFC 2822 date string 101 # should not be translated. "Sun", not "dom" 102 not_my_birthday = datetime.datetime(1979, 7, 8, 22, 00) 103 104 if self.tz_tests: 105 self.assertEquals( dateformat.format(not_my_birthday, 'r'), u'Sun, 08 Jul 1979 22:00:00 +0100')