Skip to content

Commit 1368c96

Browse files
Merge pull request #575 from ricardobranco777/timezone_aware
tests: Fix deprecation warning for utcfromtimestamp()
2 parents c4c8648 + f38fe91 commit 1368c96

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

podman/api/parse_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import ipaddress
55
import json
66
import struct
7-
from datetime import datetime
7+
from datetime import datetime, timezone
88
from typing import Any, Optional, Union
99
from collections.abc import Iterator
1010

@@ -48,7 +48,9 @@ def prepare_timestamp(value: Union[datetime, int, None]) -> Optional[int]:
4848
return value
4949

5050
if isinstance(value, datetime):
51-
delta = value - datetime.utcfromtimestamp(0)
51+
if value.tzinfo is None:
52+
value = value.replace(tzinfo=timezone.utc)
53+
delta = value - datetime.fromtimestamp(0, timezone.utc)
5254
return delta.seconds + delta.days * 24 * 3600
5355

5456
raise ValueError(f"Type '{type(value)}' is not supported by prepare_timestamp()")

0 commit comments

Comments
 (0)