summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2020-10-09 09:49:43 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2020-10-09 09:49:43 +0200
commit1b97be644dc362b92bdd8686e59245438316c147 (patch)
treead1f01592080f7cdd087948a8cef9c8066223791
parentdc83a4ff6b5045065bcc69c3a1bf83a23cf9eeb4 (diff)
Unix timestamps are assumed to be UTC.
-rw-r--r--lesana/types.py7
-rw-r--r--tests/test_types.py6
2 files changed, 10 insertions, 3 deletions
diff --git a/lesana/types.py b/lesana/types.py
index ccdaf20..0f20a75 100644
--- a/lesana/types.py
+++ b/lesana/types.py
@@ -109,7 +109,7 @@ class LesanaDecimal(LesanaType):
class LesanaTimestamp(LesanaType):
"""
- A unix timestamp
+ A unix timestamp, assumed to be UTC
"""
name = "timestamp"
@@ -119,7 +119,10 @@ class LesanaTimestamp(LesanaType):
if isinstance(data, datetime.datetime):
return data
try:
- return datetime.datetime.fromtimestamp(int(data))
+ return datetime.datetime.fromtimestamp(
+ int(data),
+ datetime.timezone.utc,
+ )
except (TypeError, ValueError):
raise LesanaValueError(
"Invalid value for timestamp field: {}".format(data)
diff --git a/tests/test_types.py b/tests/test_types.py
index 9e0c931..90f6482 100644
--- a/tests/test_types.py
+++ b/tests/test_types.py
@@ -126,7 +126,11 @@ class testTypes(unittest.TestCase):
self.assertEqual(v, now)
v = checker.load("1600000000")
- self.assertEqual(v, datetime.datetime(2020, 9, 13, 14, 26, 40))
+ wanted = datetime.datetime(
+ 2020, 9, 13, 12, 26, 40, 0,
+ datetime.timezone.utc,
+ )
+ self.assertEqual(v, wanted)
today = datetime.date.today()
for d in (