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

update to detect duplicate DTSTART/DTEND in same ics event, #348

Merged
merged 9 commits into from
Oct 28, 2024
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ END:VCALENDAR
`, function(err, data) { console.log(data); });
```

Note: When using the `ical.async.*` functions in a separate async context from your main code,
errors will be thrown in that separate context. Therefore, you must wrap these function calls
in try/catch blocks to properly handle any errors. For example:

```javascript
try {
const events = await ical.async.parseFile('calendar.ics');
// Process events
} catch (error) {
console.error('Failed to parse calendar:', error);
}
```

### autodetect
These are the old API examples, which still work and will be converted to the new API automatically.
Functions with callbacks provided will also have better performance over the older versions even if they use the old API.
Expand Down
28 changes: 20 additions & 8 deletions ical.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ const exdateParameter = function (name) {
if (typeof exdate[name].toISOString === 'function') {
curr[name][exdate[name].toISOString().slice(0, 10)] = exdate[name];
} else {
throw new TypeError('No toISOString function in exdate[name]', exdate[name]);
throw new TypeError('No toISOString function in exdate[name] = ' + exdate[name]);
}
}
}
Expand Down Expand Up @@ -548,7 +548,7 @@ module.exports = {
if (typeof curr.recurrenceid.toISOString === 'function') {
par[curr.uid].recurrences[curr.recurrenceid.toISOString().slice(0, 10)] = recurrenceObject;
} else { // Removed issue 56
throw new TypeError('No toISOString function in curr.recurrenceid', curr.recurrenceid);
throw new TypeError('No toISOString function in curr.recurrenceid =' + curr.recurrenceid);
}
}

Expand Down Expand Up @@ -623,10 +623,10 @@ module.exports = {

rule = rule.replace(/\.\d{3}/, '');
} catch (error) { // This should not happen, issue #56
throw new Error('ERROR when trying to convert to ISOString', error);
throw new Error('ERROR when trying to convert to ISOString ' + error);
}
} else {
throw new Error('No toISOString function in curr.start', curr.start);
throw new Error('No toISOString function in curr.start ' + curr.start);
}
}

Expand All @@ -645,11 +645,23 @@ module.exports = {
URL: storeParameter('url'),
UID: storeParameter('uid'),
LOCATION: storeParameter('location'),
DTSTART(value, parameters, curr, stack) {
curr = dateParameter('start')(value, parameters, curr, stack);
return typeParameter('datetype')(value, parameters, curr);
DTSTART(value, parameters, curr, stack, line) {
// If already defined, this is a duplicate for this event
if (curr.start === undefined) {
curr = dateParameter('start')(value, parameters, curr, stack);
return typeParameter('datetype')(value, parameters, curr);
}

throw new Error('duplicate DTSTART encountered, line=' + line);
},
DTEND(value, parameters, curr, stack, line) {
// If already defined, this is a duplicate for this event
if (curr.end === undefined) {
return dateParameter('end')(value, parameters, curr, stack);
}

throw new Error('duplicate DTEND encountered, line=' + line);
},
DTEND: dateParameter('end'),
EXDATE: exdateParameter('exdate'),
' CLASS': storeParameter('class'), // Should there be a space in this property?
TRANSP: storeParameter('transparency'),
Expand Down
Loading