Skip to content

Commit

Permalink
for files with multiple tzids in the VTIMEZONE, choose the last
Browse files Browse the repository at this point in the history
  • Loading branch information
sujal committed Feb 23, 2024
1 parent b4008a7 commit 2083000
Showing 1 changed file with 7 additions and 2 deletions.
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 ?
typeof vTimezone.tzid == 'object' ? 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

0 comments on commit 2083000

Please sign in to comment.