From 0b39833ff207d798dea7dd838323d78a9971df7d Mon Sep 17 00:00:00 2001 From: mmso Date: Wed, 29 Jan 2020 16:11:34 +0100 Subject: [PATCH 1/2] Fix isUTC and UTC timezone --- lib/calendar/vcal.js | 39 ++++++++++++++++++++++++++++++-------- test/calendar/vcal.spec.js | 19 +++++++++++++++++++ 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/lib/calendar/vcal.js b/lib/calendar/vcal.js index 7040e199..9393e174 100644 --- a/lib/calendar/vcal.js +++ b/lib/calendar/vcal.js @@ -227,6 +227,36 @@ const getParameters = (type, property) => { return result; }; +const modifyInternalObject = (type, internalObject) => { + if (type === 'date-time') { + const { value, parameters } = internalObject; + // eslint-disable-next-line no-mixed-operators + const tzid = (parameters && parameters.tzid) || ''; + if (tzid.toLowerCase().includes('utc')) { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { tzid: omitTzid, ...restParameters } = parameters; + return { + value: { ...value, isUTC: true }, + ...(Object.keys(restParameters).length && { parameters: restParameters }) + }; + } + return internalObject; + } + return internalObject; +}; + +const propertyToObject = (property) => { + const { type } = property; + + const values = property.getValues().map((value) => icalValueToInternalValue(type, value)); + const parameters = getParameters(type, property); + + return modifyInternalObject(type, { + value: property.isMultiValue ? values : values[0], + ...(Object.keys(parameters).length && { parameters }) + }); +}; + /** * @param {Array} properties * @return {Object} @@ -242,14 +272,7 @@ const fromIcalProperties = (properties = []) => { return acc; } - const { type } = property; - const values = property.getValues().map((value) => icalValueToInternalValue(type, value)); - - const parameters = getParameters(type, property); - const propertyAsObject = { - value: property.isMultiValue ? values : values[0], - ...(Object.keys(parameters).length && { parameters }) - }; + const propertyAsObject = propertyToObject(property); if (PROPERTIES[name] === UNIQUE) { acc[name] = propertyAsObject; diff --git a/test/calendar/vcal.spec.js b/test/calendar/vcal.spec.js index d067953d..e35f0520 100644 --- a/test/calendar/vcal.spec.js +++ b/test/calendar/vcal.spec.js @@ -101,6 +101,11 @@ END:VEVENT`; const veventsRruleYearly = [veventRruleYearly]; +const veventUTC = `BEGIN:VEVENT +DTSTART;TZID=Etc/UTC:20190101T000000 +DTEND;TZID=UTC:20190101T020000 +END:VEVENT`; + describe('calendar', () => { it('should parse vevent', () => { const result = parse(vevent); @@ -416,6 +421,20 @@ describe('calendar', () => { expect(trimAll(result)).toEqual(trimAll(allDayVevent)); }); + fit('should parse vevent with UTC timezone without appending tzid UTC', () => { + const result = parse(veventUTC); + + expect(result).toEqual({ + component: 'vevent', + dtstart: { + value: { year: 2019, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true } + }, + dtend: { + value: { year: 2019, month: 1, day: 1, hours: 2, minutes: 0, seconds: 0, isUTC: true } + } + }); + }); + it('should parse trigger string', () => { expect(fromTriggerString('-PT30M')).toEqual({ weeks: 0, From ad352dc874f68e27f3fee6237232c0e500cabab3 Mon Sep 17 00:00:00 2001 From: mmso Date: Wed, 29 Jan 2020 16:16:30 +0100 Subject: [PATCH 2/2] xit --- test/calendar/vcal.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/calendar/vcal.spec.js b/test/calendar/vcal.spec.js index e35f0520..ecd53333 100644 --- a/test/calendar/vcal.spec.js +++ b/test/calendar/vcal.spec.js @@ -421,7 +421,7 @@ describe('calendar', () => { expect(trimAll(result)).toEqual(trimAll(allDayVevent)); }); - fit('should parse vevent with UTC timezone without appending tzid UTC', () => { + it('should parse vevent with UTC timezone without appending tzid UTC', () => { const result = parse(veventUTC); expect(result).toEqual({