[calendar] add timezone parameter to calendarevent in order order do get the good date/hours in ical exports
This commit is contained in:
parent
33393780ab
commit
0936e1dfc4
6 changed files with 28 additions and 3 deletions
|
|
@ -20,6 +20,7 @@
|
|||
from __future__ import print_function
|
||||
|
||||
from datetime import time, datetime
|
||||
from dateutil import tz
|
||||
|
||||
from weboob.tools.date import parse_date
|
||||
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
|
||||
|
|
@ -54,11 +55,18 @@ class ICalFormatter(IFormatter):
|
|||
def format_obj(self, obj, alias):
|
||||
result = u'BEGIN:VEVENT\r\n'
|
||||
|
||||
utc_zone = tz.gettz('UTC')
|
||||
|
||||
event_timezone = tz.gettz(obj.timezone)
|
||||
start_date = obj.start_date if not empty(obj.start_date) else datetime.now()
|
||||
result += u'DTSTART:%s\r\n' % start_date.strftime("%Y%m%dT%H%M%SZ")
|
||||
start_date = start_date.replace(tzinfo=event_timezone)
|
||||
utc_start_date = start_date.astimezone(utc_zone)
|
||||
result += u'DTSTART:%s\r\n' % utc_start_date.strftime("%Y%m%dT%H%M%SZ")
|
||||
|
||||
end_date = obj.end_date if not empty(obj.end_date) else datetime.combine(start_date, time.max)
|
||||
result += u'DTEND:%s\r\n' % end_date.strftime("%Y%m%dT%H%M%SZ")
|
||||
end_date = end_date.replace(tzinfo=event_timezone)
|
||||
utc_end_date = end_date.astimezone(utc_zone)
|
||||
result += u'DTEND:%s\r\n' % utc_end_date.strftime("%Y%m%dT%H%M%SZ")
|
||||
|
||||
result += u'SUMMARY:%s\r\n' % obj.summary
|
||||
result += u'UID:%s\r\n' % obj.id
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class BaseCalendarEvent(BaseObject):
|
|||
url = StringField('URL of the event')
|
||||
start_date = DateField('Start date of the event')
|
||||
end_date = DateField('End date of the event')
|
||||
timezone = StringField('Timezone of the event in order to convert to utc time', default='Etc/UCT')
|
||||
summary = StringField('Title of the event')
|
||||
city = StringField('Name of the city in witch event will take place')
|
||||
location = StringField('Location of the event')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue