mirror of https://github.com/docker/docker-py.git
Fix datetime issue with Python 2.6
Signed-off-by: Christophe Labouisse <christophe@labouisse.org>
This commit is contained in:
parent
a07bd28077
commit
53b1bb41ac
|
@ -28,6 +28,7 @@ import six
|
||||||
from .. import errors
|
from .. import errors
|
||||||
from .. import tls
|
from .. import tls
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_HTTP_HOST = "127.0.0.1"
|
DEFAULT_HTTP_HOST = "127.0.0.1"
|
||||||
DEFAULT_UNIX_SOCKET = "http+unix://var/run/docker.sock"
|
DEFAULT_UNIX_SOCKET = "http+unix://var/run/docker.sock"
|
||||||
|
|
||||||
|
@ -299,7 +300,8 @@ def convert_filters(filters):
|
||||||
|
|
||||||
def datetime_to_timestamp(dt=datetime.now()):
|
def datetime_to_timestamp(dt=datetime.now()):
|
||||||
"""Convert a datetime in local timezone to a unix timestamp"""
|
"""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(
|
def create_host_config(
|
||||||
|
|
|
@ -190,10 +190,10 @@ class DockerClientTest(Cleanup, unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_events_with_since_until(self):
|
def test_events_with_since_until(self):
|
||||||
now = datetime.datetime.now()
|
ts = 1356048000
|
||||||
|
now = datetime.datetime.fromtimestamp(ts)
|
||||||
since = now - datetime.timedelta(seconds=10)
|
since = now - datetime.timedelta(seconds=10)
|
||||||
until = now + datetime.timedelta(seconds=10)
|
until = now + datetime.timedelta(seconds=10)
|
||||||
ts = int((now - datetime.datetime.fromtimestamp(0)).total_seconds())
|
|
||||||
try:
|
try:
|
||||||
self.client.events(since=since, until=until)
|
self.client.events(since=since, until=until)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -210,7 +210,8 @@ class DockerClientTest(Cleanup, unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_events_with_filters(self):
|
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:
|
try:
|
||||||
self.client.events(filters=filters)
|
self.client.events(filters=filters)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in New Issue