Skip to content

Commit

Permalink
fix issue with numbered TZID by always converting to string
Browse files Browse the repository at this point in the history
(fixes jens-maus#311).
  • Loading branch information
jens-maus authored and sujal committed May 7, 2024
1 parent 2b8a6d3 commit 4bef087
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 10 deletions.
17 changes: 7 additions & 10 deletions ical.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,17 @@ const storeParameter = function (name) {
};

const addTZ = function (dt, parameters) {
const p = parseParameters(parameters);

if (dt.tz) {
if (dt && dt.tz) {
// Date already has a timezone property
return dt;
}

if (parameters && p && dt) {
dt.tz = p.TZID;
if (dt.tz !== undefined) {
// Remove surrounding quotes if found at the beginning and at the end of the string
// (Occurs when parsing Microsoft Exchange events containing TZID with Windows standard format instead IANA)
dt.tz = dt.tz.replace(/^"(.*)"$/, '$1');
}
const p = parseParameters(parameters);
if (parameters && p && dt && typeof p.TZID !== 'undefined') {
dt.tz = p.TZID.toString();
// Remove surrounding quotes if found at the beginning and at the end of the string
// (Occurs when parsing Microsoft Exchange events containing TZID with Windows standard format instead IANA)
dt.tz = dt.tz.replace(/^"(.*)"$/, '$1');
}

return dt;
Expand Down
13 changes: 13 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,19 @@ vows
assert.equal(event.end.toDateString(), new Date(2024, 1, 22).toDateString());
}
}
},
'with test_with_int_tzid.ics': {
topic() {
return ical.parseFile('./test/test_with_int_tzid.ics');
},
'checking for TZID': {
topic(topic) {
return _.values(topic)[0];
},
'task completed'(task) {
assert.equal(task.summary, 'test export import');
}
}
}
})
.export(module);
66 changes: 66 additions & 0 deletions test/test_with_int_tzid.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
BEGIN:VCALENDAR
BEGIN:VEVENT
CREATED:20231214T150120Z
LAST-MODIFIED:20231214T150224Z
DTSTAMP:20231214T150224Z
UID:df21da35-3a0b-434a-9211-da9f9095fb16
SUMMARY:test export import
CATEGORIES:Professionnel
DTSTART;TZID=Europe/Paris:20231215T150000
DTEND;TZID=Europe/Paris:20231215T160000
TRANSP:OPAQUE
LOCATION:dijon
DESCRIPTION;ALTREP="data:text/html,test":test
END:VEVENT
BEGIN:VTIMEZONE
TZID: 1
BEGIN:STANDARD
DTSTART:16010101T030000
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20240229T160626Z
LAST-MODIFIED:20231221T141000Z
DTSTAMP:20231221T141000Z
UID:040000008200E00074C5B7101A82E008000000008D1F7DAB8632DA01000000000000000
0100000008EF89A92C90D1342BF1F2CB714276CCC
SUMMARY:Atelier groupes portail/Nuage
PRIORITY:5
STATUS:CONFIRMED
DTSTART;TZID= 1:20240108T110000
DTEND;TZID= 1:20240108T120000
CLASS:PUBLIC
DESCRIPTION;LANGUAGE=fr-FR:Désolé pour ces changements de date\, j'espèr
e que ce dernier créneau conviendra à tout le monde. \n\nJe vous propose
cette date pour un atelier sur les soucis avec les commandes à passer sur
les serveurs nextcloud pour la mise en place des groupes. Dites moi si ça
ne convient pas. Merci !\n
TRANSP:OPAQUE
SEQUENCE:3
LOCATION;LANGUAGE=fr-FR:https://visio-agents.education.fr/
X-MICROSOFT-CDO-APPT-SEQUENCE:3
X-MICROSOFT-CDO-OWNERAPPTID:2122095757
X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-CDO-INSTTYPE:0
X-MICROSOFT-DONOTFORWARDMEETING:FALSE
X-MICROSOFT-DISALLOW-COUNTER:FALSE
X-MICROSOFT-LOCATIONDISPLAYNAME:https://visio-agents.education.fr/
X-MICROSOFT-LOCATIONSOURCE:None
X-MICROSOFT-LATITUDE:0
X-MICROSOFT-LONGITUDE:0
X-MOZ-RECEIVED-SEQUENCE:3
X-MOZ-RECEIVED-DTSTAMP:20231221T141000Z
END:VEVENT
END:VCALENDAR

0 comments on commit 4bef087

Please sign in to comment.