From 60d4a87cb5655af9e3a848385ba925f2165bba9d Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 9 Jul 2022 13:10:53 +0200 Subject: save timestamps in UTC For the most part, we want to know the instant of when something happened. To stay consistent, we save everything as UTC. For internal things, this doesn't really matter - we just need to know the timezone to be able to compare the values (like "is the upload older than 5 days"). For user-facing things (like comments), we still want to store the UTC time and then convert it to the user's preferred timezone on display. --- fietsboek/models/user.py | 4 ++-- fietsboek/views/detail.py | 2 +- fietsboek/views/profile.py | 2 +- fietsboek/views/upload.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fietsboek/models/user.py b/fietsboek/models/user.py index c8296c6..84aa4d9 100644 --- a/fietsboek/models/user.py +++ b/fietsboek/models/user.py @@ -286,7 +286,7 @@ class Token(Base): :vartype uuid: str :ivar token_type: The type of the token. :vartype token_type: TokenType - :ivar date: Date of the token creation. + :ivar date: Date of the token creation, in UTC. :vartype date: datetime.datetime :ivar user: User that this token belongs to. :vartype user: User @@ -313,7 +313,7 @@ class Token(Base): :rtype: Token """ token_uuid = str(uuid.uuid4()) - now = datetime.datetime.now() + now = datetime.datetime.utcnow() return cls(user=user, uuid=token_uuid, date=now, token_type=token_type) diff --git a/fietsboek/views/detail.py b/fietsboek/views/detail.py index 5d969e7..9153047 100644 --- a/fietsboek/views/detail.py +++ b/fietsboek/views/detail.py @@ -81,7 +81,7 @@ def add_comment(request): comment = models.Comment( track=track, author=request.identity, - date=datetime.datetime.now(), + date=datetime.datetime.utcnow(), title=request.params["title"], text=request.params["comment"], ) diff --git a/fietsboek/views/profile.py b/fietsboek/views/profile.py index 7085c56..ad481db 100644 --- a/fietsboek/views/profile.py +++ b/fietsboek/views/profile.py @@ -95,7 +95,7 @@ def do_add_friend(request): friend_req = models.FriendRequest( sender=request.identity, recipient=candidate, - date=datetime.datetime.now(), + date=datetime.datetime.utcnow(), ) request.dbsession.add(friend_req) request.session.flash(request.localizer.translate(_("flash.friend_request_sent"))) diff --git a/fietsboek/views/upload.py b/fietsboek/views/upload.py index 4db0cd6..7a1059b 100644 --- a/fietsboek/views/upload.py +++ b/fietsboek/views/upload.py @@ -62,7 +62,7 @@ def do_upload(request): LOGGER.info("Could not parse gpx: %s", exc) return HTTPFound(request.route_url('upload')) - now = datetime.datetime.now() + now = datetime.datetime.utcnow() upload = models.Upload( owner=request.identity, -- cgit v1.2.3