mirror of https://github.com/docker/docker-py.git
utils: Fix datetime_to_timestamp
Replace usage of deprecated function `datetime.utcfromtimestamp` and make sure the input date is UTC before subtracting. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
parent
6ceb08273c
commit
1784cc2962
|
|
@ -5,7 +5,7 @@ import os
|
|||
import os.path
|
||||
import shlex
|
||||
import string
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from packaging.version import Version
|
||||
|
||||
from .. import errors
|
||||
|
|
@ -394,8 +394,8 @@ def convert_filters(filters):
|
|||
|
||||
|
||||
def datetime_to_timestamp(dt):
|
||||
"""Convert a UTC datetime to a Unix timestamp"""
|
||||
delta = dt - datetime.utcfromtimestamp(0)
|
||||
"""Convert a datetime to a Unix timestamp"""
|
||||
delta = dt.astimezone(timezone.utc) - datetime(1970, 1, 1, tzinfo=timezone.utc)
|
||||
return delta.seconds + delta.days * 24 * 3600
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue