Skip to content
Snippets Groups Projects
Commit 53c252f0 authored by Antony Sande's avatar Antony Sande
Browse files

fix(parser): convert dates to ISO-Strings

Return all dates (`start`, `end`, and `createdAt`) as ISO-Strings,
instead of Date objects to maintain consistency.

BREAKING CHANGE:

The dates were returned as a mix of ISO-Strings and Date Objects
in previous versions.

To migrate your project, confirm that you are handling the dates
received from scrapegoat correctly.
parent 06a6ee77
Branches
No related tags found
No related merge requests found
......@@ -82,7 +82,11 @@ function getNormalizedEndDate(endDate, duration) {
// CalDav saves the end date of all day events as the start of the next day
// To fix this, we subtract one second from the end date
return allDayEvent ? moment(endDate).subtract(1, "seconds").toISOString() : endDate;
return (
allDayEvent ?
new Date(moment(endDate).subtract(1, "seconds")) :
endDate
).toISOString();
}
function getNormalOccurenceEventData(nextEvent, eventData, vevent) {
......@@ -96,11 +100,11 @@ function getNormalOccurenceEventData(nextEvent, eventData, vevent) {
uid,
location,
description,
start: new Date(dtstart),
start: new Date(dtstart).toISOString(),
end: getNormalizedEndDate(new Date(dtend), duration),
duration,
type: { recurring: true, edited: false },
createdAt: new Date(vevent.getFirstPropertyValue("created"))
createdAt: new Date(vevent.getFirstPropertyValue("created")).toISOString()
};
}
......@@ -114,11 +118,11 @@ function getModifiedOccurenceEventData(vevent, eventData) {
uid: vevent.getFirstPropertyValue("uid"),
location: vevent.getFirstPropertyValue("location"),
description: vevent.getFirstPropertyValue("description"),
start: new Date(dtstart),
start: new Date(dtstart).toISOString(),
end: getNormalizedEndDate(new Date(dtend), duration),
duration,
type: { recurring: true, edited: true },
createdAt: new Date(vevent.getFirstPropertyValue("created"))
createdAt: new Date(vevent.getFirstPropertyValue("created")).toISOString()
};
}
......@@ -218,11 +222,11 @@ function parseEvents(xml) {
uid: vevent.getFirstPropertyValue("uid"),
location: vevent.getFirstPropertyValue("location"),
description: vevent.getFirstPropertyValue("description"),
start: new Date(dtstart),
start: new Date(dtstart).toISOString(),
end: getNormalizedEndDate(new Date(dtend), duration),
duration,
type: { recurring: false, edited: false },
createdAt: new Date(vevent.getFirstPropertyValue("created"))
createdAt: new Date(vevent.getFirstPropertyValue("created")).toISOString()
};
formatted.push({
......@@ -234,8 +238,8 @@ function parseEvents(xml) {
});
formatted.sort((a, b) => {
const aStart = new ICAL.Time().fromJSDate(a.data.start);
const bStart = new ICAL.Time().fromJSDate(b.data.start);
const aStart = new ICAL.Time().fromJSDate(new Date(a.data.start));
const bStart = new ICAL.Time().fromJSDate(new Date(b.data.start));
return aStart.compare(bStart);
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment