Skip to content

Commit

Permalink
utils: Fix datetime_to_timestamp
Browse files Browse the repository at this point in the history
Replace usage of deprecated function `datetime.utcfromtimestamp` and
make sure the input date is UTC before subtracting.

Signed-off-by: Paweł Gronowski <[email protected]>
  • Loading branch information
vvoland committed Dec 22, 2023
1 parent 6ceb082 commit 1784cc2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docker/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 1784cc2

Please sign in to comment.