mirror of
https://github.com/django/django.git
synced 2024-11-18 23:44:22 +00:00
d4bb582b1a
to not assume TZ absolutely will be set in the environment. That environment variable does not necessarily exist on Windows, it seems. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11699 bcc190cf-cafb-0310-a4f2-bffc1f526a37
46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
import os
|
|
from unittest import TestCase
|
|
from datetime import datetime, date
|
|
from django.utils.dateformat import format
|
|
from django.utils.tzinfo import FixedOffset, LocalTimezone
|
|
|
|
class DateFormatTests(TestCase):
|
|
def setUp(self):
|
|
self.old_TZ = os.environ.get('TZ')
|
|
os.environ['TZ'] = 'Europe/Copenhagen'
|
|
|
|
def tearDown(self):
|
|
if self.old_TZ is None:
|
|
del os.environ['TZ']
|
|
else:
|
|
os.environ['TZ'] = self.old_TZ
|
|
|
|
def test_date(self):
|
|
d = date(2009, 5, 16)
|
|
self.assertEquals(date.fromtimestamp(int(format(d, 'U'))), d)
|
|
|
|
def test_naive_datetime(self):
|
|
dt = datetime(2009, 5, 16, 5, 30, 30)
|
|
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U'))), dt)
|
|
|
|
def test_datetime_with_local_tzinfo(self):
|
|
ltz = LocalTimezone(datetime.now())
|
|
dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=ltz)
|
|
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), ltz), dt)
|
|
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U'))), dt.replace(tzinfo=None))
|
|
|
|
def test_datetime_with_tzinfo(self):
|
|
tz = FixedOffset(-510)
|
|
ltz = LocalTimezone(datetime.now())
|
|
dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=tz)
|
|
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), tz), dt)
|
|
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), ltz), dt)
|
|
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U'))), dt.astimezone(ltz).replace(tzinfo=None))
|
|
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), tz).utctimetuple(), dt.utctimetuple())
|
|
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), ltz).utctimetuple(), dt.utctimetuple())
|
|
|
|
def test_epoch(self):
|
|
utc = FixedOffset(0)
|
|
udt = datetime(1970, 1, 1, tzinfo=utc)
|
|
self.assertEquals(format(udt, 'U'), u'0')
|