Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for files with multiple tzids in the VTIMEZONE, choose the last #307

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ical.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,13 @@ const dateParameter = function (name) {
const vTimezone =
Object.values(stackItemWithTimeZone).find(({type}) => type === 'VTIMEZONE');

newDate = vTimezone && moment.tz.zone(vTimezone.tzid) ?
moment.tz(value, 'YYYYMMDDTHHmmss', vTimezone.tzid).toDate() :
// If the VTIMEZONE contains multiple TZIDs, use the last one in order
const normalizedTzId = vTimezone ?
(Array.isArray(vTimezone.tzid) ? vTimezone.tzid[vTimezone.tzid.length - 1] : vTimezone.tzid) :
null;

newDate = normalizedTzId && moment.tz.zone(normalizedTzId) ?
moment.tz(value, 'YYYYMMDDTHHmmss', normalizedTzId).toDate() :
new Date(
Number.parseInt(comps[1], 10),
Number.parseInt(comps[2], 10) - 1,
Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,22 @@ vows
assert.equal(topic.start.tz, 'Europe/Berlin');
}
}
},
'with test_with_multiple_tzids_in_vtimezone.ics': {
topic() {
return ical.parseFile('./test/test_with_multiple_tzids_in_vtimezone.ics');
},
'using a vtimezone with multiple timezone': {
topic(events) {
return _.select(_.values(events), x => {
return x.uid === '1891-1709856000-1709942399@www.washougal.k12.wa.us';
})[0];
},
'has a start'(topic) {
assert.equal(topic.start.toJSON(), '2024-06-27T07:00:00.000Z');
assert.equal(topic.end.toJSON(), '2024-06-28T06:00:00.000Z');
}
}
}
})
.export(module);
46 changes: 46 additions & 0 deletions test/test_with_multiple_tzids_in_vtimezone.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Hathaway Elementary School - ECPv6.3.3//NONSGML v1.0//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Hathaway Elementary School
X-ORIGINAL-URL:https://www.washougal.k12.wa.us/hathaway
X-WR-CALDESC:Events for Hathaway Elementary School
REFRESH-INTERVAL;VALUE=DURATION:PT1H
X-Robots-Tag:noindex
X-PUBLISHED-TTL:PT1H
BEGIN:VTIMEZONE
TZID:Africa/Abidjan
BEGIN:STANDARD
TZOFFSETFROM:+0000
TZOFFSETTO:+0000
TZNAME:GMT
DTSTART:20240101T000000
END:STANDARD
TZID:America/Los_Angeles
BEGIN:DAYLIGHT
TZOFFSETFROM:-0800
TZOFFSETTO:-0700
TZNAME:PDT
DTSTART:20240310T100000
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0700
TZOFFSETTO:-0800
TZNAME:PST
DTSTART:20241103T090000
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART:20240627T000000
DTEND:20240627T230000
DTSTAMP:20240222T162327
CREATED:20231129T014844Z
LAST-MODIFIED:20240222T184259Z
UID:1891-1709856000-1709942399@www.washougal.k12.wa.us
SUMMARY:Possible Snow Makeup Day
DESCRIPTION:This day is a snow makeup day\, and will be added back to the calendar if needed. If we do not have any snow closure\, this is a non-attendance day for students.  \nFor a list of all calendar related closures and important dates\, please visit our calendar page at https://www.washougal.k12.wa.us/calendar/
URL:https://www.washougal.k12.wa.us/hathaway/event/possible-snow-makeup-day/
CATEGORIES:School Events
END:VEVENT
END:VCALENDAR
Loading