Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.
Draft
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
39 changes: 31 additions & 8 deletions lib/calendar/vcal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions test/calendar/vcal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -416,6 +421,20 @@ describe('calendar', () => {
expect(trimAll(result)).toEqual(trimAll(allDayVevent));
});

it('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,
Expand Down