Skip to content

Commit

Permalink
making datetimes to ui timezone aware. closes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
Juca Crispim committed Oct 25, 2017
1 parent b3677a9 commit bcc414d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/unit/core/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions toxicbuild/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit bcc414d

Please sign in to comment.