Mercurial > code > home > repos > gcalendarwatch
changeset 21:9eb6b4806272
timmzone fixes, especially on GET /events
author | drewp@bigasterisk.com |
---|---|
date | Mon, 08 Feb 2021 16:40:47 -0800 |
parents | 8c7af0d1b118 |
children | 8122ff3b0fe5 |
files | Dockerfile gcalendarwatch.py |
diffstat | 2 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Dockerfile Thu Oct 29 23:48:35 2020 -0700 +++ b/Dockerfile Mon Feb 08 16:40:47 2021 -0800 @@ -1,14 +1,15 @@ FROM ubuntu:focal +RUN apt-get update ENV TZ=America/Los_Angeles ENV LANG=en_US.UTF-8 RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata WORKDIR /opt -RUN apt-get update RUN apt-get install -y python3-pip RUN apt-get install -y git
--- a/gcalendarwatch.py Thu Oct 29 23:48:35 2020 -0700 +++ b/gcalendarwatch.py Mon Feb 08 16:40:47 2021 -0800 @@ -270,6 +270,8 @@ self.collection = collection def getEvents(self, t1, t2): + if t1.tzinfo is None or t2.tzinfo is None: + raise TypeError("tz-naive datetimes") for doc in self.collection.find({"startTime": {"$gte": t1, "$lt": t2}}).sort([("startTime", 1)]): doc['uri'] = doc.pop('_id') if 'feedId' in doc: @@ -341,9 +343,12 @@ upcoming events as JSON-LD """ arg = self.get_argument - t1 = parse(arg('t1')) if arg('t1', default=None) else datetime.datetime.now().replace(hour=0, minute=0, second=0) - t2 = parse(arg('t2')) if arg('t2', - default=None) else datetime.datetime.now() + datetime.timedelta(days=int(arg('days')) if arg('days', default=None) else 2) + t1, t2 = dayRange(int(arg('days', default='2'))) + if arg('t1', default=None): + t1 = parse(arg('t1'), tzinfo=tzlocal()) + if arg('t2', default=None): + t2 = parse(arg('t2'), tzinfo=tzlocal()) + log.info(f'get /events local t1={t1} t2={t2}') if 0: self.set_header("content-type", "application/ld+json") self.write(asJsonLd(self.settings.read.getEvents(t1, t2)))