Browse Source

Respect timezone when converting datetime objects to epoch

tags/0.1
Johann Schmitz 3 years ago
parent
commit
073d269ecf
Signed by: ercpe <johann@j-schmitz.net> GPG Key ID: A084064277C501ED
2 changed files with 4 additions and 4 deletions
  1. +3
    -3
      tests/test_updates.py
  2. +1
    -1
      tvdbrest/client.py

+ 3
- 3
tests/test_updates.py View File

@@ -41,7 +41,7 @@ class TestUpdateAPI(TestBase):
def test_updated_with_datetimes(self, urlencode_mock, tvdb):
tvdb._api_request = mock.MagicMock()

dt = datetime.datetime(2017, 2, 26, 17, 00, 00, tzinfo=datetime.timezone.utc)
dt = datetime.datetime(2017, 2, 26, 16, 00, 00, tzinfo=datetime.timezone.utc)
tvdb.updates(dt)
urlencode_mock.assert_called_with({
@@ -52,8 +52,8 @@ class TestUpdateAPI(TestBase):
def test_updated_with_datetimes_to(self, urlencode_mock, tvdb):
tvdb._api_request = mock.MagicMock()
dt1 = datetime.datetime(2017, 2, 26, 17, 00, 00, tzinfo=datetime.timezone.utc)
dt2 = datetime.datetime(2017, 2, 26, 18, 00, 00, tzinfo=datetime.timezone.utc)
dt1 = datetime.datetime(2017, 2, 26, 16, 00, 00, tzinfo=datetime.timezone.utc)
dt2 = datetime.datetime(2017, 2, 26, 17, 00, 00, tzinfo=datetime.timezone.utc)
tvdb.updates(dt1, to_time=dt2)
urlencode_mock.assert_called_with({


+ 1
- 1
tvdbrest/client.py View File

@@ -199,7 +199,7 @@ class TVDB(object):
u = '/updated/query?'
def _dt_to_epoch(o):
return int(time.mktime(o.timetuple())) if isinstance(o, datetime.datetime) else o
return int(time.mktime(o.timetuple())) - time.timezone if isinstance(o, datetime.datetime) else o
kwargs = {
'fromTime': _dt_to_epoch(from_time)


Loading…
Cancel
Save