Browse Source

Respect timezone when converting datetime objects to epoch

tags/0.1
Johann Schmitz 2 years ago
parent
commit
073d269ecf
Signed by: Johann Schmitz <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):
41 41
     def test_updated_with_datetimes(self, urlencode_mock, tvdb):
42 42
         tvdb._api_request = mock.MagicMock()
43 43
 
44
-        dt = datetime.datetime(2017, 2, 26, 17, 00, 00, tzinfo=datetime.timezone.utc)
44
+        dt = datetime.datetime(2017, 2, 26, 16, 00, 00, tzinfo=datetime.timezone.utc)
45 45
         tvdb.updates(dt)
46 46
         
47 47
         urlencode_mock.assert_called_with({
@@ -52,8 +52,8 @@ class TestUpdateAPI(TestBase):
52 52
     def test_updated_with_datetimes_to(self, urlencode_mock, tvdb):
53 53
         tvdb._api_request = mock.MagicMock()
54 54
     
55
-        dt1 = datetime.datetime(2017, 2, 26, 17, 00, 00, tzinfo=datetime.timezone.utc)
56
-        dt2 = datetime.datetime(2017, 2, 26, 18, 00, 00, tzinfo=datetime.timezone.utc)
55
+        dt1 = datetime.datetime(2017, 2, 26, 16, 00, 00, tzinfo=datetime.timezone.utc)
56
+        dt2 = datetime.datetime(2017, 2, 26, 17, 00, 00, tzinfo=datetime.timezone.utc)
57 57
         tvdb.updates(dt1, to_time=dt2)
58 58
     
59 59
         urlencode_mock.assert_called_with({

+ 1
- 1
tvdbrest/client.py View File

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

Loading…
Cancel
Save