Fix cannot import UTC

This commit is contained in:
grossmj 2024-05-09 17:23:32 +07:00
parent 33499be425
commit 259d3a0155
No known key found for this signature in database
GPG Key ID: 0A2D76AC45EA25CD

View File

@ -24,7 +24,7 @@ import aiofiles
import zipfile import zipfile
import time import time
import aiohttp.web import aiohttp.web
from datetime import datetime, timezone, UTC from datetime import datetime, timezone
from ..utils.asyncio import wait_run_in_executor from ..utils.asyncio import wait_run_in_executor
from ..utils.asyncio import aiozipstream from ..utils.asyncio import aiozipstream
@ -52,15 +52,15 @@ class Snapshot:
self._project = project self._project = project
if name: if name:
self._name = name self._name = name
self._created_at = datetime.now().timestamp() self._created_at = datetime.now(timezone.utc).timestamp()
filename = self._name + "_" + datetime.fromtimestamp(self._created_at, UTC).replace(tzinfo=None).strftime(FILENAME_TIME_FORMAT) + ".gns3project" filename = self._name + "_" + datetime.fromtimestamp(self._created_at, tz=timezone.utc).replace(tzinfo=None).strftime(FILENAME_TIME_FORMAT) + ".gns3project"
else: else:
self._name = filename.split("_")[0] self._name = filename.split("_")[0]
datestring = filename.replace(self._name + "_", "").split(".")[0] datestring = filename.replace(self._name + "_", "").split(".")[0]
try: try:
self._created_at = datetime.strptime(datestring, FILENAME_TIME_FORMAT).replace(tzinfo=timezone.utc).timestamp() self._created_at = datetime.strptime(datestring, FILENAME_TIME_FORMAT).replace(tzinfo=timezone.utc).timestamp()
except ValueError: except ValueError:
self._created_at = datetime.now(UTC) self._created_at = datetime.now(timezone.utc)
self._path = os.path.join(project.path, "snapshots", filename) self._path = os.path.join(project.path, "snapshots", filename)
@property @property