Skip to content

Commit 42b712d

Browse files
committed
Merge pull request #680 from aanand/fix-timestamp-conversion
Enforce UTC datetimes in arguments to `events()`
2 parents 2c08ad2 + 657420a commit 42b712d

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

docker/utils/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ def convert_filters(filters):
339339
return json.dumps(result)
340340

341341

342-
def datetime_to_timestamp(dt=datetime.now()):
343-
"""Convert a datetime in local timezone to a unix timestamp"""
344-
delta = dt - datetime.fromtimestamp(0)
342+
def datetime_to_timestamp(dt):
343+
"""Convert a UTC datetime to a Unix timestamp"""
344+
delta = dt - datetime.utcfromtimestamp(0)
345345
return delta.seconds + delta.days * 24 * 3600
346346

347347

docs/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ function return a blocking generator you can iterate over to retrieve events as
251251

252252
**Params**:
253253

254-
* since (datetime or int): get events from this point
255-
* until (datetime or int): get events until this point
254+
* since (UTC datetime or int): get events from this point
255+
* until (UTC datetime or int): get events until this point
256256
* filters (dict): filter the events by event time, container or image
257257
* decode (bool): If set to true, stream will be decoded into dicts on the
258258
fly. False by default.

tests/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def test_events(self):
221221

222222
def test_events_with_since_until(self):
223223
ts = 1356048000
224-
now = datetime.datetime.fromtimestamp(ts)
224+
now = datetime.datetime.utcfromtimestamp(ts)
225225
since = now - datetime.timedelta(seconds=10)
226226
until = now + datetime.timedelta(seconds=10)
227227
try:

0 commit comments

Comments
 (0)