Store times in UTC
This commit is contained in:
parent
d68d77e6d5
commit
dc29de90f8
|
@ -22,4 +22,4 @@ class OutputHandler(object):
|
|||
return repo, archive, cache
|
||||
|
||||
def get_borg_error(self):
|
||||
return Error(self.borg_output, datetime.now())
|
||||
return Error(self.borg_output, datetime.utcnow())
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from .connection import RepoConn, ArchiveConn, ErrorConn, LabelConn, CacheConn
|
||||
from .object import Repo, Archive, Label, Error
|
||||
from .object.label import Label
|
||||
from pathlib import Path
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class ErrorConn(DatabaseConnection):
|
|||
statement = f"INSERT INTO {self._sql_table}"\
|
||||
f" ('label_id', 'error', 'time')"\
|
||||
f" VALUES (?, ?, ?);"
|
||||
args = (label_id, record.error, datetime.now())
|
||||
args = (label_id, record.error, datetime.utcnow())
|
||||
cursor.execute(statement, args)
|
||||
self.sql_commit()
|
||||
return cursor.lastrowid
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from . import DBObject
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
class Archive(DBObject):
|
||||
|
@ -19,8 +19,8 @@ class Archive(DBObject):
|
|||
def from_json(cls, json: dict):
|
||||
fingerprint = json['id']
|
||||
name = json['name']
|
||||
start = datetime.fromisoformat(json['start'])
|
||||
end = datetime.fromisoformat(json['end'])
|
||||
start = datetime.fromisoformat(json['start']).astimezone(tz=timezone.utc).replace(tzinfo=None)
|
||||
end = datetime.fromisoformat(json['end']).astimezone(tz=timezone.utc).replace(tzinfo=None)
|
||||
|
||||
stats_json = json['stats']
|
||||
file_count = stats_json['nfiles']
|
||||
|
@ -48,6 +48,6 @@ class Archive(DBObject):
|
|||
# region GET
|
||||
|
||||
def seconds_since(self) -> float:
|
||||
return (datetime.now() - self.start).total_seconds()
|
||||
return (datetime.utcnow() - self.start).total_seconds()
|
||||
|
||||
# endregion
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from . import DBObject
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
class Error(DBObject):
|
||||
|
@ -11,7 +11,7 @@ class Error(DBObject):
|
|||
@classmethod
|
||||
def from_json(cls, json: dict):
|
||||
error = json['error']
|
||||
time = datetime.fromisoformat(json['time'])
|
||||
time = datetime.fromisoformat(json['time']).astimezone(tz=timezone.utc).replace(tzinfo=None)
|
||||
return cls(error, time)
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from . import DBObject
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
|
@ -16,7 +16,9 @@ class Repo(DBObject):
|
|||
def from_json(cls, json: dict):
|
||||
uuid = json['id']
|
||||
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)
|
||||
|
||||
@classmethod
|
||||
|
@ -28,6 +30,6 @@ class Repo(DBObject):
|
|||
# region GET
|
||||
|
||||
def seconds_since(self) -> float:
|
||||
return (datetime.now() - self.last_modified).total_seconds()
|
||||
return (datetime.utcnow() - self.last_modified).total_seconds()
|
||||
|
||||
# endregion
|
||||
|
|
Loading…
Reference in New Issue
Block a user