Ticket #9762: rfc2822.3.diff

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

restored system settings.LANGUAGE_CODE after monkeying around

  • django/utils/dateformat.py

     
    1414import re
    1515import time
    1616import calendar
     17from email.utils import formatdate
    1718from django.utils.dates import MONTHS, MONTHS_3, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR
    1819from django.utils.tzinfo import LocalTimezone
    1920from django.utils.translation import ugettext as _
     
    172173
    173174    def r(self):
    174175        "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)
    176180
    177181    def S(self):
    178182        "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, translation
    31from unittest import TestCase
    42import datetime, os, time
     3from django.conf import settings
     4from django.utils import dateformat, translation
    55
    66class DateFormatTests(TestCase):
    77    def setUp(self):
    88        self.old_TZ = os.environ.get('TZ')
    99        os.environ['TZ'] = 'Europe/Copenhagen'
    1010        translation.activate('en-us')
     11        self.original_language = settings.LANGUAGE_CODE
     12        settings.LANGUAGE_CODE = 'en'
    1113
    1214        try:
    1315            # Check if a timezone has been set
     
    1820            self.tz_tests = False
    1921
    2022    def tearDown(self):
     23        settings.LANGUAGE_CODE = self.original_language
    2124        if self.old_TZ is None:
    2225            del os.environ['TZ']
    2326        else:
     
    8285
    8386        if self.tz_tests:
    8487            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')
    8689            self.assertEquals(dateformat.format(my_birthday, 'T'), u'CET')
    8790            self.assertEquals(dateformat.format(my_birthday, 'U'), u'300315600')
    8891            self.assertEquals(dateformat.format(my_birthday, 'Z'), u'3600')
     
    9093            self.assertEquals(dateformat.format(summertime, 'O'), u'+0200')
    9194            self.assertEquals(dateformat.format(wintertime, 'I'), u'0')
    9295            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')
Back to Top