aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-07-09 13:10:53 +0200
committerDaniel Schadt <kingdread@gmx.de>2022-07-09 13:10:53 +0200
commit60d4a87cb5655af9e3a848385ba925f2165bba9d (patch)
treebccf8e17cf6bca187ee3980fdf6ac29ac1912aa2
parent6e18519c93ff34d864029ae1d9b2aa03ac2f7f53 (diff)
downloadfietsboek-60d4a87cb5655af9e3a848385ba925f2165bba9d.tar.gz
fietsboek-60d4a87cb5655af9e3a848385ba925f2165bba9d.tar.bz2
fietsboek-60d4a87cb5655af9e3a848385ba925f2165bba9d.zip
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.
-rw-r--r--fietsboek/models/user.py4
-rw-r--r--fietsboek/views/detail.py2
-rw-r--r--fietsboek/views/profile.py2
-rw-r--r--fietsboek/views/upload.py2
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,