From 5fc92aa67c0d81a3df8493e855249e3afb084dcf Mon Sep 17 00:00:00 2001 From: Dominik George <nik@naturalnet.de> Date: Sat, 17 Oct 2020 22:35:59 +0200 Subject: [PATCH] Make default timezone configurable. Closes #17 --- base-config.yaml | 3 +++ reminder/util.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/base-config.yaml b/base-config.yaml index f868c3f..a42dbdc 100644 --- a/base-config.yaml +++ b/base-config.yaml @@ -3,3 +3,6 @@ base_command: - remind - reminder + +# Default timezone for users who did not set one +timezone: 'UTC' diff --git a/reminder/util.py b/reminder/util.py index a29992a..99c291a 100644 --- a/reminder/util.py +++ b/reminder/util.py @@ -35,6 +35,7 @@ if TYPE_CHECKING: class Config(BaseProxyConfig): def do_update(self, helper: ConfigUpdateHelper) -> None: helper.copy("base_command") + helper.copy("timezone") class DateArgument(Argument): @@ -43,7 +44,10 @@ class DateArgument(Argument): def match(self, val: str, evt: MessageEvent = None, instance: 'ReminderBot' = None ) -> Tuple[str, Optional[datetime]]: - tz = pytz.UTC + try: + tz = pytz.timezone(instance.config["timezone"]) + except (pytz.UnknownTimeZoneError, StopIteration, IndexError): + tz = pytz.UTC use_locales = [locales["en_iso"]] if instance: tz = instance.db.get_timezone(evt.sender) -- GitLab