Skip to content

Commit

Permalink
Merge pull request #626 from euphorie/localize-time
Browse files Browse the repository at this point in the history
The dates are returned naive, localize them with the proper timezone
  • Loading branch information
ale-rt authored Jul 17, 2023
2 parents 8b726b7 + ab06ebf commit 4600f7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/euphorie/client/adapters/history_item.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from euphorie.client import MessageFactory as _
from euphorie.client.model import SessionEvent
from euphorie.client.model import show_timezone
from euphorie.client.model import SurveySession
from json import JSONDecodeError
from json import loads
Expand Down Expand Up @@ -79,6 +80,13 @@ def note(self):
)
return {}

@property
def raw_time(self):
"""The dates are returned naive, localize them with the proper timezone"""
time = getattr(self.context, self.time_attribute)
timezone = show_timezone()
return timezone.localize(time)

def session_url(self):
session = self.context.session
return "{tool_url}/++session++{session_id}".format(
Expand Down
7 changes: 7 additions & 0 deletions src/euphorie/client/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import datetime
import logging
import OFS.Traversable
import pytz
import random
import re

Expand Down Expand Up @@ -1982,6 +1983,12 @@ def __call__(self):
return self.request.response.redirect(target)


@ram.cache(lambda _: "show_timezone_cache_key")
def show_timezone():
timezone = Session.execute("SHOW TIMEZONE").first()
return pytz.timezone(timezone[0])


__all__ = [
"SurveySession",
"Module",
Expand Down

0 comments on commit 4600f7f

Please sign in to comment.