From bcc414d0d6be23a7b46a709515045aad6eefaef7 Mon Sep 17 00:00:00 2001 From: Juca Crispim Date: Wed, 25 Oct 2017 03:23:55 -0200 Subject: [PATCH] making datetimes to ui timezone aware. closes #24 --- tests/unit/core/test_utils.py | 5 +++++ toxicbuild/core/utils.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/tests/unit/core/test_utils.py b/tests/unit/core/test_utils.py index 6eaa9315..a4e58539 100644 --- a/tests/unit/core/test_utils.py +++ b/tests/unit/core/test_utils.py @@ -171,7 +171,12 @@ def test_datetime2string(self): dt = utils.now() expected = datetime.datetime.strftime(dt, '%a %b %d %H:%M:%S %Y %z') returned = utils.datetime2string(dt) + self.assertEqual(returned, expected) + def test_datetime2string_timezone(self): + dt = utils.localtime2utc(utils.now()) + expected = datetime.datetime.strftime(dt, '%a %b %d %H:%M:%S %Y %z') + returned = utils.datetime2string(datetime.datetime.now()) self.assertEqual(returned, expected) def test_datetime2string_with_other_format(self): diff --git a/toxicbuild/core/utils.py b/toxicbuild/core/utils.py index 704a92a0..7823b302 100644 --- a/toxicbuild/core/utils.py +++ b/toxicbuild/core/utils.py @@ -171,6 +171,8 @@ def datetime2string(dt, dtformat='%a %b %d %H:%M:%S %Y %z'): :param dt: The datetime object. :param dtformat: The format to use.""" + if dt.utcoffset() is None: + dt = localtime2utc(dt) return datetime.strftime(dt, dtformat)