kopia lustrzana https://github.com/jazzband/icalevents
chore: add test for per-event timezone where required
rodzic
d1c11aa2e0
commit
9829e80486
|
@ -167,11 +167,12 @@ def encode(value: Optional[vText]) -> Optional[str]:
|
||||||
return str(value.encode("utf-8"))
|
return str(value.encode("utf-8"))
|
||||||
|
|
||||||
|
|
||||||
def create_event(component, utc_default, strict):
|
def create_event(component, strict):
|
||||||
"""
|
"""
|
||||||
Create an event from its iCal representation.
|
Create an event from its iCal representation.
|
||||||
|
|
||||||
:param component: iCal component
|
:param component: iCal component
|
||||||
|
:param strict:
|
||||||
:return: event
|
:return: event
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -323,11 +324,9 @@ def parse_events(
|
||||||
|
|
||||||
# If there's exactly one timezone in the file,
|
# If there's exactly one timezone in the file,
|
||||||
# assume it applies globally, otherwise UTC
|
# assume it applies globally, otherwise UTC
|
||||||
utc_default = False
|
|
||||||
if len(timezones) == 1:
|
if len(timezones) == 1:
|
||||||
cal_tz = get_timezone(list(timezones)[0])
|
cal_tz = get_timezone(list(timezones)[0])
|
||||||
else:
|
else:
|
||||||
utc_default = True
|
|
||||||
cal_tz = UTC
|
cal_tz = UTC
|
||||||
# < ==========================================
|
# < ==========================================
|
||||||
|
|
||||||
|
@ -358,7 +357,7 @@ def parse_events(
|
||||||
exceptions[exdate[0:8]] = exdate
|
exceptions[exdate[0:8]] = exdate
|
||||||
|
|
||||||
if component.name == "VEVENT":
|
if component.name == "VEVENT":
|
||||||
e = create_event(component, utc_default, strict)
|
e = create_event(component, strict)
|
||||||
|
|
||||||
# make rule.between happy and provide from, to points in time that have the same format as dtstart
|
# make rule.between happy and provide from, to points in time that have the same format as dtstart
|
||||||
s = component["dtstart"].dt
|
s = component["dtstart"].dt
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
BEGIN:VCALENDAR
|
||||||
|
PRODID:-//Google Inc//Google Calendar 70.9054//EN
|
||||||
|
VERSION:2.0
|
||||||
|
CALSCALE:GREGORIAN
|
||||||
|
METHOD:PUBLISH
|
||||||
|
X-WR-CALNAME:test
|
||||||
|
X-WR-TIMEZONE:Europe/Zurich
|
||||||
|
BEGIN:VTIMEZONE
|
||||||
|
TZID:Europe/Zurich
|
||||||
|
X-LIC-LOCATION:Europe/Zurich
|
||||||
|
BEGIN:DAYLIGHT
|
||||||
|
TZOFFSETFROM:+0100
|
||||||
|
TZOFFSETTO:+0200
|
||||||
|
TZNAME:GMT+2
|
||||||
|
DTSTART:19700329T020000
|
||||||
|
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
|
||||||
|
END:DAYLIGHT
|
||||||
|
BEGIN:STANDARD
|
||||||
|
TZOFFSETFROM:+0200
|
||||||
|
TZOFFSETTO:+0100
|
||||||
|
TZNAME:GMT+1
|
||||||
|
DTSTART:19701025T030000
|
||||||
|
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
|
||||||
|
END:STANDARD
|
||||||
|
END:VTIMEZONE
|
||||||
|
BEGIN:VEVENT
|
||||||
|
DTSTART;TZID=Europe/Zurich:20240325T070000
|
||||||
|
DTEND;TZID=Europe/Zurich:20240325T080000
|
||||||
|
DTSTAMP:20240908T134310Z
|
||||||
|
UID:21u17g5sbq791pn23imf7ue0lc@google.com
|
||||||
|
CREATED:20240908T134239Z
|
||||||
|
LAST-MODIFIED:20240908T134239Z
|
||||||
|
SEQUENCE:0
|
||||||
|
STATUS:CONFIRMED
|
||||||
|
SUMMARY:Zürich
|
||||||
|
TRANSP:OPAQUE
|
||||||
|
END:VEVENT
|
||||||
|
BEGIN:VEVENT
|
||||||
|
DTSTART;TZID=Australia/Perth:20240325T070000
|
||||||
|
DTEND;TZID=Australia/Perth:20240325T080000
|
||||||
|
DTSTAMP:20240908T134310Z
|
||||||
|
UID:21u17g5sbq791pn23imf7ue0ld@google.com
|
||||||
|
CREATED:20240908T134239Z
|
||||||
|
LAST-MODIFIED:20240908T134239Z
|
||||||
|
SEQUENCE:0
|
||||||
|
STATUS:CONFIRMED
|
||||||
|
SUMMARY:Perth
|
||||||
|
TRANSP:OPAQUE
|
||||||
|
END:VEVENT
|
||||||
|
END:VCALENDAR
|
|
@ -902,6 +902,19 @@ class ICalEventsTests(unittest.TestCase):
|
||||||
self.assertEqual(evs[3].start, datetime(2022, 6, 8, 13, 00, 0, tzinfo=tz))
|
self.assertEqual(evs[3].start, datetime(2022, 6, 8, 13, 00, 0, tzinfo=tz))
|
||||||
self.assertEqual(evs[3].summary, "Recurring Event")
|
self.assertEqual(evs[3].summary, "Recurring Event")
|
||||||
|
|
||||||
|
def test_per_event_timezone(self):
|
||||||
|
ical = "test/test_data/per_event_timezone.ics"
|
||||||
|
start = date(2024, 1, 1)
|
||||||
|
end = date(2024, 12, 30)
|
||||||
|
|
||||||
|
events = icalevents.events(file=ical, start=start, end=end, strict=True)
|
||||||
|
self.assertEqual(
|
||||||
|
events[0].start.tzname(), "CET", "check tz as specified in calendar"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
events[1].start.tzname(), "AWST", "check tz as specified in calendar"
|
||||||
|
)
|
||||||
|
|
||||||
def test_regression_repeating_events_raise_an_error(self):
|
def test_regression_repeating_events_raise_an_error(self):
|
||||||
ical = "test/test_data/recurrence_tzinfo.ics"
|
ical = "test/test_data/recurrence_tzinfo.ics"
|
||||||
start = date(2023, 1, 1)
|
start = date(2023, 1, 1)
|
||||||
|
|
Ładowanie…
Reference in New Issue