Skip to content

Commit 53b1bb4

Browse files
committed
Fix datetime issue with Python 2.6
Signed-off-by: Christophe Labouisse <[email protected]>
1 parent a07bd28 commit 53b1bb4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

docker/utils/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .. import errors
2929
from .. import tls
3030

31+
3132
DEFAULT_HTTP_HOST = "127.0.0.1"
3233
DEFAULT_UNIX_SOCKET = "http+unix://var/run/docker.sock"
3334

@@ -299,7 +300,8 @@ def convert_filters(filters):
299300

300301
def datetime_to_timestamp(dt=datetime.now()):
301302
"""Convert a datetime in local timezone to a unix timestamp"""
302-
return int((dt - datetime.fromtimestamp(0)).total_seconds())
303+
delta = dt - datetime.fromtimestamp(0)
304+
return delta.seconds + delta.days * 24 * 3600
303305

304306

305307
def create_host_config(

tests/test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ def test_events(self):
190190
)
191191

192192
def test_events_with_since_until(self):
193-
now = datetime.datetime.now()
193+
ts = 1356048000
194+
now = datetime.datetime.fromtimestamp(ts)
194195
since = now - datetime.timedelta(seconds=10)
195196
until = now + datetime.timedelta(seconds=10)
196-
ts = int((now - datetime.datetime.fromtimestamp(0)).total_seconds())
197197
try:
198198
self.client.events(since=since, until=until)
199199
except Exception as e:
@@ -210,7 +210,8 @@ def test_events_with_since_until(self):
210210
)
211211

212212
def test_events_with_filters(self):
213-
filters = {'event': ['die', 'stop'], 'container': fake_api.FAKE_CONTAINER_ID}
213+
filters = {'event': ['die', 'stop'],
214+
'container': fake_api.FAKE_CONTAINER_ID}
214215
try:
215216
self.client.events(filters=filters)
216217
except Exception as e:

0 commit comments

Comments
 (0)