Do not parse dates #1
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Right now dates are parsed and then output into the merged file in a different format.
If I change the date lines to this, it imports fine into nextcloud, which failed before:
fixed the code to output the dates in the desired format compatible with nextcloud.
before
DTSTART:${event.start} DTEND:${event.end}
after:
DTSTART;VALUE=DATE:${event.start.toISOString().split('T')[0].replace(/-/g, '')} DTEND;VALUE=DATE:${event.end.toISOString().split('T')[0].replace(/-/g, '')}
In this updated code, I'm using the toISOString() method to convert the start and end dates to ISO format, I then use the split('T')[0] method to extract the date part (without the time part). The replace(/-/g, '') method is used to remove the hyphens from the date string.
This now generates the DTSTART and DTEND lines in the format you suggested for Nextcloud.
Ah the ical library already parses the date, now I got it.
The problem with this new approach is that I think it only supports dates, but time-based events should be supported too.
You can use this URL to test date-based events, and then add one yourself for time-based events: https://www.schulferien.org/media/ical/deutschland/ferien_bayern_2023.ics?k=PsL0S2B9rScFMn5PAxtf4OVQjMkWZsqqkK13zEJ0FCW5Q-2xQejfLJYaTN4EdYUsQHLDDbGVnVl93ms7en5vMUISjZ3H9Esu88Vp2ndnL5Q
I've made the changes to support time based events as well.
thanks, please add test data into the samples for that :)
Changes made:
before :
DTSTART;VALUE=DATE:${event.start.toISOString().split('T')[0].replace(/-/g, '')} DTEND;VALUE=DATE:${event.end.toISOString().split('T')[0].replace(/-/g, '')}
After:
DTSTART;VALUE=DATETIME:${event.start.toISOString().replace(/-|:|\.\d{3}/g, '')} DTEND;VALUE=DATETIME:${event.end.toISOString().replace(/-|:|\.\d{3}/g, '')}
Explanation of Changes
VALUE=DATETIME:
This indicates that the event has specific start and end times.Formatting: The
toISOString()
method returns a string in the formatYYYY-MM-DDTHH:mm:ss.sssZ
. The regex replacement removes the hyphens, colons, and milliseconds to match the iCalendar format, which is typicallyYYYYMMDDTHHMMSSZ
.Sample from test data:
BEGIN:VEVENT
DTSTART;VALUE=DATETIME:20241009T173000Z
DTEND;VALUE=DATETIME:20241009T183000Z
SUMMARY:work do
END:VEVENT
From the test links in the calendar.json, the merged calendar now captures both date and time if specified.
Ideally you can solve this by using https://www.npmjs.com/package/ical-generator instead of generating the ics feed manually