[B.END] Timezones management

Achtung! compatibility with current JS is not verified
This commit is contained in:
giuliof 2018-11-24 12:06:20 +01:00
parent ae296f7b93
commit 4b63a58bc2
2 changed files with 17 additions and 2 deletions

View File

@ -16,4 +16,5 @@
# Calendar related variables
[caldav]
cal_name =
cal_name =
local_tz =

View File

@ -4,6 +4,7 @@ import datetime as dt
import sys
import re
import glob
import pytz
def parseOptions(arr):
if len(arr) == 1:
@ -67,11 +68,24 @@ def getEvents(baseDay, interval):
event_dict['NAME'] = k[1]
elif k[0] == 'DTSTART':
options = parseOptions(k[1:])
if 'TZID' in options:
event_tz = pytz.timezone(options['TZID'])
event_fmt = "%Y%m%dT%H%M%S"
# If TZID flag is not specified, datetime is UTC
else:
event_tz = pytz.timezone('UTC')
event_fmt = "%Y%m%dT%H%M%SZ"
# Check if time is set and then localize it
if 'VALUE' in options and options['VALUE'] == 'DATE':
event_dict['DATETIME'] = dt.datetime.strptime(options['RAW'],'%Y%m%d')
event_dict['ALLDAY'] = True
else:
event_dict['DATETIME'] = dt.datetime.strptime(options['RAW'],'%Y%m%dT%H%M%S')
event_parsed_dt = dt.datetime.strptime(options['RAW'], event_fmt)
event_parsed_dt = event_parsed_dt.replace(tzinfo=event_tz)
local_tz = pytz.timezone(glob.cfg['caldav']['local_tz'])
event_dict['DATETIME'] = event_parsed_dt.astimezone(local_tz)
event_dict['ALLDAY'] = False
elif k[0] == 'LOCATION':
event_dict['LOCATION'] = k[1]