Fix time formatting for timezone values
Fixes: https://pagure.io/koji/issue/2423
This commit is contained in:
parent
44db1bc8ee
commit
b0efed5e37
2 changed files with 50 additions and 3 deletions
|
|
@ -1,5 +1,7 @@
|
|||
from __future__ import absolute_import
|
||||
import datetime
|
||||
import os
|
||||
import time
|
||||
import locale
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
|
|
@ -11,6 +13,16 @@ import six.moves.xmlrpc_client as xmlrpc_client
|
|||
from koji import formatTime, formatTimeLong
|
||||
|
||||
class TestFormatTime(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self._orig_tz = os.environ.get('TZ')
|
||||
|
||||
def tearDown(self):
|
||||
if self._orig_tz:
|
||||
os.environ['TZ'] = self._orig_tz
|
||||
elif 'TZ' in os.environ:
|
||||
del os.environ['TZ']
|
||||
time.tzset()
|
||||
|
||||
def test_format_time(self):
|
||||
self.assertEqual(formatTime(None), '')
|
||||
self.assertEqual(formatTime(''), '')
|
||||
|
|
@ -33,6 +45,8 @@ class TestFormatTime(unittest.TestCase):
|
|||
def test_format_time_long(self):
|
||||
# force locale to compare 'desired' value
|
||||
locale.setlocale(locale.LC_ALL, ('en_US', 'UTF-8'))
|
||||
os.environ['TZ'] = 'GMT'
|
||||
time.tzset()
|
||||
|
||||
self.assertEqual(formatTimeLong(None), '')
|
||||
self.assertEqual(formatTimeLong(''), '')
|
||||
|
|
@ -62,4 +76,28 @@ class TestFormatTime(unittest.TestCase):
|
|||
r = r[:r.rfind(' ')]
|
||||
self.assertEqual(r, desired)
|
||||
|
||||
# str + timezone
|
||||
d3 = '2017-10-05 09:52:31+02:00'
|
||||
desired = 'Thu, 05 Oct 2017 07:52:31 GMT'
|
||||
os.environ['TZ'] = 'GMT'
|
||||
time.tzset()
|
||||
r = formatTimeLong(d3)
|
||||
self.assertEqual(r, desired)
|
||||
|
||||
# non-GMT without DST
|
||||
d3 = '2017-06-05 09:52:31+02:00'
|
||||
desired = 'Mon, 05 Jun 2017 09:52:31 CEST'
|
||||
os.environ['TZ'] = 'Europe/Prague'
|
||||
time.tzset()
|
||||
r = formatTimeLong(d3)
|
||||
self.assertEqual(r, desired)
|
||||
|
||||
# non-GMT with DST
|
||||
d3 = '2017-12-05 09:52:31+02:00'
|
||||
desired = 'Tue, 05 Dec 2017 08:52:31 CET'
|
||||
os.environ['TZ'] = 'Europe/Prague'
|
||||
time.tzset()
|
||||
r = formatTimeLong(d3)
|
||||
self.assertEqual(r, desired)
|
||||
|
||||
locale.resetlocale()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue