From 947cf2845a23d01c070c43825662327cef7a16d0 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 23 Feb 2016 13:52:12 +0100 Subject: * store event dates as UTC --- rcal/model.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/rcal/model.py b/rcal/model.py index 2c09e6c..34390c7 100644 --- a/rcal/model.py +++ b/rcal/model.py @@ -1,8 +1,21 @@ # pylint: disable=too-few-public-methods, invalid-name +from dateutil.tz import tzutc from sqlalchemy import Column, ForeignKey from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship -from sqlalchemy.types import Boolean, Date, Integer, String +from sqlalchemy.types import Boolean, DateTime, Integer, String, TIMESTAMP, TypeDecorator + +class UTCDateTime(TypeDecorator): + impl = DateTime + + def process_bind_param(self, value, engine): + if value is not None: + return value.astimezone(tzutc()) + + def process_result_value(self, value, engine): + if value is not None: + return value.replace(tzinfo=tzutc()) + BASE = declarative_base() @@ -15,6 +28,7 @@ class Calendar(BASE): name = Column(String(255), index=True) website = Column(String(255)) visible = Column(Boolean, index=True) + last_updated = Column(TIMESTAMP) _category = Column( Integer, @@ -53,8 +67,8 @@ class Entry(BASE): id = Column(Integer, primary_key=True) uid = Column(String(255), index=True, unique=True) - begin_date = Column(Date, index=True) - end_date = Column(Date) + begin_date = Column(UTCDateTime, index=True) + end_date = Column(UTCDateTime) all_day = Column(Boolean) name = Column(String(255)) location = Column(String(255)) -- cgit v1.2.3