Skip to content

Commit

Permalink
Fix Python 3.12 DeprecationWarning for utcfromtimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
titusz committed Dec 7, 2023
1 parent d0a5fc3 commit 1521026
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions iscc_core/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from datetime import datetime
import sys
import datetime
import random
from typing import List, Union
import base58
Expand Down Expand Up @@ -350,10 +351,14 @@ def iscc(self):
)

@property
def time(self):
def time(self): # pragma: no cover
"""Time component as string in ISO 8601 format"""
ts = int.from_bytes(self._flake[0:6], "big", signed=False) / 1000
return datetime.utcfromtimestamp(ts).isoformat(timespec="milliseconds")
if sys.version_info >= (3, 12):
dt = datetime.datetime.fromtimestamp(ts, datetime.timezone.utc)
else:
dt = datetime.datetime.utcfromtimestamp(ts)
return dt.isoformat(timespec="milliseconds").replace("+00:00", "")

@property
def int(self):
Expand Down

0 comments on commit 1521026

Please sign in to comment.