summaryrefslogtreecommitdiff
path: root/rcal
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-02-23 13:52:12 +0100
committeremkael <emkael@tlen.pl>2016-02-23 13:52:12 +0100
commit947cf2845a23d01c070c43825662327cef7a16d0 (patch)
tree527777ccdc93684999dd6a0b1f2d2c13425ccba3 /rcal
parent7a384588d8cf273ec078d3370eebc4087eb92d75 (diff)
* store event dates as UTC
Diffstat (limited to 'rcal')
-rw-r--r--rcal/model.py20
1 files 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))