Store times in UTC

This commit is contained in:
George Lacey 2021-05-06 10:08:48 +01:00
parent d68d77e6d5
commit dc29de90f8
6 changed files with 13 additions and 12 deletions

View File

@ -22,4 +22,4 @@ class OutputHandler(object):
return repo, archive, cache return repo, archive, cache
def get_borg_error(self): def get_borg_error(self):
return Error(self.borg_output, datetime.now()) return Error(self.borg_output, datetime.utcnow())

View File

@ -1,5 +1,4 @@
from .connection import RepoConn, ArchiveConn, ErrorConn, LabelConn, CacheConn from .connection import RepoConn, ArchiveConn, ErrorConn, LabelConn, CacheConn
from .object import Repo, Archive, Label, Error
from .object.label import Label from .object.label import Label
from pathlib import Path from pathlib import Path

View File

@ -35,7 +35,7 @@ class ErrorConn(DatabaseConnection):
statement = f"INSERT INTO {self._sql_table}"\ statement = f"INSERT INTO {self._sql_table}"\
f" ('label_id', 'error', 'time')"\ f" ('label_id', 'error', 'time')"\
f" VALUES (?, ?, ?);" f" VALUES (?, ?, ?);"
args = (label_id, record.error, datetime.now()) args = (label_id, record.error, datetime.utcnow())
cursor.execute(statement, args) cursor.execute(statement, args)
self.sql_commit() self.sql_commit()
return cursor.lastrowid return cursor.lastrowid

View File

@ -1,5 +1,5 @@
from . import DBObject from . import DBObject
from datetime import datetime from datetime import datetime, timezone
class Archive(DBObject): class Archive(DBObject):
@ -19,8 +19,8 @@ class Archive(DBObject):
def from_json(cls, json: dict): def from_json(cls, json: dict):
fingerprint = json['id'] fingerprint = json['id']
name = json['name'] name = json['name']
start = datetime.fromisoformat(json['start']) start = datetime.fromisoformat(json['start']).astimezone(tz=timezone.utc).replace(tzinfo=None)
end = datetime.fromisoformat(json['end']) end = datetime.fromisoformat(json['end']).astimezone(tz=timezone.utc).replace(tzinfo=None)
stats_json = json['stats'] stats_json = json['stats']
file_count = stats_json['nfiles'] file_count = stats_json['nfiles']
@ -48,6 +48,6 @@ class Archive(DBObject):
# region GET # region GET
def seconds_since(self) -> float: def seconds_since(self) -> float:
return (datetime.now() - self.start).total_seconds() return (datetime.utcnow() - self.start).total_seconds()
# endregion # endregion

View File

@ -1,5 +1,5 @@
from . import DBObject from . import DBObject
from datetime import datetime from datetime import datetime, timezone
class Error(DBObject): class Error(DBObject):
@ -11,7 +11,7 @@ class Error(DBObject):
@classmethod @classmethod
def from_json(cls, json: dict): def from_json(cls, json: dict):
error = json['error'] error = json['error']
time = datetime.fromisoformat(json['time']) time = datetime.fromisoformat(json['time']).astimezone(tz=timezone.utc).replace(tzinfo=None)
return cls(error, time) return cls(error, time)
@classmethod @classmethod

View File

@ -1,5 +1,5 @@
from . import DBObject from . import DBObject
from datetime import datetime from datetime import datetime, timezone
from pathlib import Path from pathlib import Path
@ -16,7 +16,9 @@ class Repo(DBObject):
def from_json(cls, json: dict): def from_json(cls, json: dict):
uuid = json['id'] uuid = json['id']
location = Path(json['location']) location = Path(json['location'])
last_modified = datetime.fromisoformat(json['last_modified']) last_modified = datetime.fromisoformat(json['last_modified'])\
.astimezone(tz=timezone.utc)\
.replace(tzinfo=None)
return cls(uuid, location, last_modified) return cls(uuid, location, last_modified)
@classmethod @classmethod
@ -28,6 +30,6 @@ class Repo(DBObject):
# region GET # region GET
def seconds_since(self) -> float: def seconds_since(self) -> float:
return (datetime.now() - self.last_modified).total_seconds() return (datetime.utcnow() - self.last_modified).total_seconds()
# endregion # endregion