Commit 0a6f1e2e authored by Lysander Trischler's avatar Lysander Trischler

Fix timezone comparison problem when adding weights

parent 294415ea
......@@ -160,6 +160,13 @@ if __name__ == "__main__":
return self._now
@property
def utcnow(self):
if not hasattr(self, "_utcnow"):
self._utcnow = pytz.UTC.localize(datetime.datetime.utcnow())
return self._utcnow
@property
def today(self):
"""
......@@ -1077,18 +1084,22 @@ if __name__ == "__main__":
else:
try:
date = tornadyse.dtutils.parse_datetime(date)
if date.tzinfo is None:
date = berlin.localize(date)
else:
date = date.astimezone(berlin)
except Exception as e:
self.error_messages.append("Fehlerhafte Messzeitpunktangabe: %r" % e)
self.set_status(400)
else:
# date cannot be more than one week
if date > (self.now + datetime.timedelta(days=7)):
if date > self.utcnow + datetime.timedelta(days=7):
self.error_messages.append("Der Messzeitpunkt liegt zu weit in der Zukunft!")
self.set_status(400)
# date cannot be before 1970-01-01 00:00:00
if date < datetime.datetime(year=1970, month=1, day=1):
if date < datetime.datetime(year=1970, month=1, day=1, tzinfo=pytz.UTC):
self.error_messages.append("Der Messzeitpunkt liegt zu weit in der Vergangenheit!")
self.set_status(400)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment