summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <f.joffrey@gmail.com>2015-07-21 10:45:29 -0700
committerJoffrey F <f.joffrey@gmail.com>2015-07-21 10:45:29 -0700
commit42b712d1005bb24b776733556ac48d8db69a1dbf (patch)
treeb381dc1ac8dffd9a675124eb93bac1dfba926e27
parent2c08ad21dd9aa0c01936e6184574cd105a2b3f64 (diff)
parent657420a4d3b1611cedf37f801e597456133807a2 (diff)
downloaddocker-py-42b712d1005bb24b776733556ac48d8db69a1dbf.tar.gz
Merge pull request #680 from aanand/fix-timestamp-conversion
Enforce UTC datetimes in arguments to `events()`
-rw-r--r--docker/utils/utils.py6
-rw-r--r--docs/api.md4
-rw-r--r--tests/test.py2
3 files changed, 6 insertions, 6 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 10c08de..a714c97 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -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
diff --git a/docs/api.md b/docs/api.md
index 2dd175a..d35e083 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -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.
diff --git a/tests/test.py b/tests/test.py
index 3171bf9..9e12bb8 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -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: