From 1784cc2962529dac8ea9aa8f3ecc5798f600b6e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 22 Dec 2023 10:20:12 +0100 Subject: [PATCH] utils: Fix datetime_to_timestamp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace usage of deprecated function `datetime.utcfromtimestamp` and make sure the input date is UTC before subtracting. Signed-off-by: Paweł Gronowski --- docker/utils/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 759ddd2f1..dbd513030 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -5,7 +5,7 @@ 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