Do not parse dates #1

Open
opened 2024-10-09 19:59:15 +00:00 by janek · 6 comments
Contributor

image

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:

DTSTART;VALUE=DATE:20230220
DTEND;VALUE=DATE:20230225
![image](/attachments/99178bff-163d-4061-b444-c29c7937af2c) 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: ``` DTSTART;VALUE=DATE:20230220 DTEND;VALUE=DATE:20230225 ```
155 KiB
Owner

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.

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.
Author
Contributor

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

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
Owner

I've made the changes to support time based events as well.

I've made the changes to support time based events as well.
Author
Contributor

thanks, please add test data into the samples for that :)

thanks, please add test data into the samples for that :)
Owner

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 format YYYY-MM-DDTHH:mm:ss.sssZ. The regex replacement removes the hyphens, colons, and milliseconds to match the iCalendar format, which is typically YYYYMMDDTHHMMSSZ.

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.

## 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 format `YYYY-MM-DDTHH:mm:ss.sssZ`. The regex replacement removes the hyphens, colons, and milliseconds to match the iCalendar format, which is typically `YYYYMMDDTHHMMSSZ`. ## 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.
Author
Contributor

Ideally you can solve this by using https://www.npmjs.com/package/ical-generator instead of generating the ics feed manually

Ideally you can solve this by using https://www.npmjs.com/package/ical-generator instead of generating the ics feed manually
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: ryanmwangi/CalMerger#1
No description provided.