Fix datetime issue with Python 2.6

Signed-off-by: Christophe Labouisse <christophe@labouisse.org>
This commit is contained in:
Christophe Labouisse 2015-02-07 19:36:45 +01:00
parent a07bd28077
commit 53b1bb41ac
2 changed files with 7 additions and 4 deletions

View File

@ -28,6 +28,7 @@ import six
from .. import errors
from .. import tls
DEFAULT_HTTP_HOST = "127.0.0.1"
DEFAULT_UNIX_SOCKET = "http+unix://var/run/docker.sock"
@ -299,7 +300,8 @@ def convert_filters(filters):
def datetime_to_timestamp(dt=datetime.now()):
"""Convert a datetime in local timezone to a unix timestamp"""
return int((dt - datetime.fromtimestamp(0)).total_seconds())
delta = dt - datetime.fromtimestamp(0)
return delta.seconds + delta.days * 24 * 3600
def create_host_config(

View File

@ -190,10 +190,10 @@ class DockerClientTest(Cleanup, unittest.TestCase):
)
def test_events_with_since_until(self):
now = datetime.datetime.now()
ts = 1356048000
now = datetime.datetime.fromtimestamp(ts)
since = now - datetime.timedelta(seconds=10)
until = now + datetime.timedelta(seconds=10)
ts = int((now - datetime.datetime.fromtimestamp(0)).total_seconds())
try:
self.client.events(since=since, until=until)
except Exception as e:
@ -210,7 +210,8 @@ class DockerClientTest(Cleanup, unittest.TestCase):
)
def test_events_with_filters(self):
filters = {'event': ['die', 'stop'], 'container': fake_api.FAKE_CONTAINER_ID}
filters = {'event': ['die', 'stop'],
'container': fake_api.FAKE_CONTAINER_ID}
try:
self.client.events(filters=filters)
except Exception as e: