Merge pull request #680 from aanand/fix-timestamp-conversion

Enforce UTC datetimes in arguments to `events()`
This commit is contained in:
Joffrey F 2015-07-21 10:45:29 -07:00
commit 42b712d100
3 changed files with 6 additions and 6 deletions

View File

@ -339,9 +339,9 @@ def convert_filters(filters):
return json.dumps(result)
def datetime_to_timestamp(dt=datetime.now()):
"""Convert a datetime in local timezone to a unix timestamp"""
delta = dt - datetime.fromtimestamp(0)
def datetime_to_timestamp(dt):
"""Convert a UTC datetime to a Unix timestamp"""
delta = dt - datetime.utcfromtimestamp(0)
return delta.seconds + delta.days * 24 * 3600

View File

@ -251,8 +251,8 @@ function return a blocking generator you can iterate over to retrieve events as
**Params**:
* since (datetime or int): get events from this point
* until (datetime or int): get events until this point
* since (UTC datetime or int): get events from this point
* until (UTC datetime or int): get events until this point
* filters (dict): filter the events by event time, container or image
* decode (bool): If set to true, stream will be decoded into dicts on the
fly. False by default.

View File

@ -221,7 +221,7 @@ class DockerClientTest(Cleanup, base.BaseTestCase):
def test_events_with_since_until(self):
ts = 1356048000
now = datetime.datetime.fromtimestamp(ts)
now = datetime.datetime.utcfromtimestamp(ts)
since = now - datetime.timedelta(seconds=10)
until = now + datetime.timedelta(seconds=10)
try: