Skip to content

Commit b04ca6b

Browse files
committed
BUG: keep the timezone info when converting to string
1 parent cac347d commit b04ca6b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

yaml2ics.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
}
2727

2828

29-
def datetime2utc(date):
29+
def datetime_to_str(date):
3030
if isinstance(date, datetime.datetime):
31-
return datetime.datetime.strftime(date, "%Y%m%dT%H%M%S")
31+
return datetime.datetime.strftime(date, "%Y%m%dT%H%M%S%z")
3232
elif isinstance(date, datetime.date):
33-
return datetime.datetime.strftime(date, "%Y%m%d")
33+
return datetime.datetime.strftime(date, "%Y%m%d%z")
3434

3535

3636
def utcnow():
@@ -122,12 +122,12 @@ def event_from_yaml(event_yaml: dict, tz: datetime.tzinfo = None) -> ics.Event:
122122
)
123123

124124
if "except_on" in repeat:
125-
exdates = [datetime2utc(rdate) for rdate in repeat["except_on"]]
126-
add_recurrence_property(event, "EXDATE", exdates)
125+
exdates = [datetime_to_str(rdate) for rdate in repeat["except_on"]]
126+
add_recurrence_property(event, "EXDATE", exdates, tz)
127127

128128
if "also_on" in repeat:
129-
rdates = [datetime2utc(rdate) for rdate in repeat["also_on"]]
130-
add_recurrence_property(event, "RDATE", rdates)
129+
rdates = [datetime_to_str(rdate) for rdate in repeat["also_on"]]
130+
add_recurrence_property(event, "RDATE", rdates, tz)
131131

132132
event.dtstamp = utcnow()
133133
if tz and event.floating and not event.all_day:

0 commit comments

Comments
 (0)