naimo84 / node-red-contrib-ical-events

Node-RED module to get events from a iCal Calender (Google e.g.), icloud or Caldav Server via kalender-events
MIT License
47 stars 12 forks source link

[BUG]: allDay property is set to true for non-all-day events #171

Open Programie opened 9 months ago

Programie commented 9 months ago

Describe the bug I have some events which don't have an end-date (i.e. the end date is the same as the start date). Every calendar application is correctly handling that event as a non-all-day event. But in case of this Node-RED module, those events are flagged as all-day events (i.e. allDay of those events is set to true).

To Reproduce Steps to reproduce the behavior:

  1. Create an event on your calendar server and select the same date/time for start date and end date
  2. Connect a trigger to the "upcoming" node and connect that node to a debug node
  3. Trigger the node
  4. The data shown in the debug node includes allDay: true for the previously created non-all-day event

Expected behavior The event should have allDay: false in case the event is not an all-day event.

node-red-contrib-ical-events

Logs / Additional context Example calendar file:

BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//SabreDAV//SabreDAV//EN
X-WR-CALNAME:Test
X-APPLE-CALENDAR-COLOR:#499AA2
REFRESH-INTERVAL;VALUE=DURATION:PT4H
X-PUBLISHED-TTL:PT4H
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20240216T195606Z
DTSTAMP:20240216T195900Z
LAST-MODIFIED:20240216T195900Z
SEQUENCE:3
UID:27d5b79f-bfb0-4f22-874f-e81e8162e074
DTSTART;TZID=Europe/Berlin:20240220T100000
DTEND;TZID=Europe/Berlin:20240220T100000
STATUS:CONFIRMED
SUMMARY:Test
END:VEVENT
END:VCALENDAR

JSON output from the "upcoming" node:

[
    {
        "date": "2/20/24, 10:00 AM",
        "eventStart": "2024-02-20T09:00:00.000Z",
        "eventEnd": "2024-02-20T09:00:00.000Z",
        "summary": "Test",
        "duration": "PT0S",
        "durationSeconds": 0,
        "rruleText": null,
        "uid": {
            "uid": "27d5b79f-bfb0-4f22-874f-e81e8162e074",
            "date": "1708419600000"
        },
        "isRecurring": false,
        "datetype": "date",
        "allDay": true,
        "calendarName": "Test",
        "originalEvent": {
            "component": [
                "vevent",
                [
                    [
                        "created",
                        {},
                        "date-time",
                        "2024-02-16T19:56:06Z"
                    ],
                    [
                        "dtstamp",
                        {},
                        "date-time",
                        "2024-02-16T19:59:00Z"
                    ],
                    [
                        "last-modified",
                        {},
                        "date-time",
                        "2024-02-16T19:59:00Z"
                    ],
                    [
                        "sequence",
                        {},
                        "integer",
                        3
                    ],
                    [
                        "uid",
                        {},
                        "text",
                        "27d5b79f-bfb0-4f22-874f-e81e8162e074"
                    ],
                    [
                        "dtstart",
                        {
                            "tzid": "Europe/Berlin"
                        },
                        "date-time",
                        "2024-02-20T10:00:00"
                    ],
                    [
                        "dtend",
                        {
                            "tzid": "Europe/Berlin"
                        },
                        "date-time",
                        "2024-02-20T10:00:00"
                    ],
                    [
                        "status",
                        {},
                        "text",
                        "CONFIRMED"
                    ],
                    [
                        "summary",
                        {},
                        "text",
                        "Test"
                    ]
                ],
                []
            ],
            "_rangeExceptionCache": {},
            "exceptions": {},
            "rangeExceptions": []
        },
        "countdown": {
            "days": 3,
            "hours": 13,
            "minutes": 0,
            "seconds": 51
        },
        "on": false
    }
]
Programie commented 2 months ago

As this is still an issue, I've looked for a workaround and found a way to check whether the event is a non-all-day event while the start and end times are the same.

It's quite easy but I didn't saw that before: Just check whether durationSeconds is zero. If that's the case, the event should not be an all-day event. Checking whether eventStart and eventEnd are the same should also work, but I guess it could have different values if eventStart and eventEnd use different time zones.