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)