Commit 56283f7a authored by Lysander Trischler's avatar Lysander Trischler

Convert GPX UTC timestamps to Europe/Berlin on view

parent c7fde194
......@@ -12,6 +12,8 @@ if __name__ == "__main__":
import hashlib
import locale
locale.setlocale(locale.LC_ALL, 'de_DE.utf8')
import pytz
berlin = pytz.timezone("Europe/Berlin")
import tornado.options
import tornado.database
......@@ -46,6 +48,16 @@ if __name__ == "__main__":
return "%.2f km" % (dist / 1000.)
def utc_to_local(utc_dt):
"""
Converts a given date time in UTC to local time using Europe/Berlin as
timezone. Used for GPX file dates in UTC to be converted to the user's
local timezone (for now Europe/Berlin).
"""
if utc_dt.tzinfo is None:
utc_dt = pytz.UTC.localize(utc_dt)
return utc_dt.astimezone(berlin)
class ColorIterator(object):
def __init__(self, *colors):
self.colors = colors or ["navy", "green", "purple", "orange", "yellow", "red", "black"]
......@@ -203,6 +215,14 @@ if __name__ == "__main__":
self._exercise = Exercise(id=self.exercise_id, username=self.username, count=self.count, discipline=self.discipline)
return self._exercise
@property
def start(self):
return utc_to_local(self["start"])
@property
def end(self):
return utc_to_local(self["end"])
@route(r'/')
class HomeHandler(BaseHandler):
def get(self):
......
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