Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rrules and dayllght savings

I'm using rrule to create and store events in my database.

All was working until I found that my recurring events had an one hour difference past the 31st march.

In France, it's the day when we do a daylight saving time change.

Actually, my events are stored in a mongo database, with the start date and the duration of the event, + the eventuals rrules (all events aren't recurring events) like this :

{
    "_id" : ObjectId("5c8e4706703df43859aabbe7"),
    "duration" : 2879,
    "type" : "unavailability",
    "title" : "Weekend",
    "description" : "C'est le weekend",
    "rrules" : [ 
        {
            "until" : ISODate("2021-03-22T23:00:00.000Z"),
            "dtstart" : ISODate("2019-03-11T23:00:00.000Z"),
            "byweekday" : [ 
                {
                    "weekday" : 5
                }, 
                {
                    "weekday" : 6
                }
            ],
            "interval" : 1,
            "freq" : 2
        }
    ],
    "__v" : 0
}

When the frontend search for a date in the calendar, it will search with this args :

?from=2019-03-10T23:00:00.000Z&to=2019-03-17T23:00:00.000Z

It works well with this date, because no daylight savings are occuring in between. If I have this object :

normalizedDates = { from: 2019-03-10T23:00:00.000Z, to: 2019-03-17T23:00:00.000Z }

and this rule :

{ until: 2021-03-22T23:00:00.000Z,
  dtstart: 2019-03-11T23:00:00.000Z,
  byweekday: [ { weekday: 5 }, { weekday: 6 } ],
  interval: 1,
  freq: 2 }

Running :

const recurringDays = rruleSet.between(normalizedDates.from, normalizedDates.to)

shows, indeed :

recurringDays [ 2019-03-23T23:00:00.000Z ]

But if y use :

normalizedDates = { from: 2019-03-31T22:00:00.000Z, to: 2019-04-07T22:00:00.000Z }

Rrules returns :

recurringDays [ 2019-03-31T23:00:00.000Z, 2019-04-06T23:00:00.000Z ]

while I'm expecting :

recurringDays [ 2019-04-06T22:00:00.000Z ]

Do you know how I could handle this ?

like image 228
Kai23 Avatar asked Nov 24 '25 19:11

Kai23


1 Answers

If you want a recurrence rule to observe daylight saving time for a particular time zone, then you must schedule using this time zone. In your example, the schedule is based on UTC.

RRule provides time zone support. You should use that, and specify tzid: 'Europe/Paris'.

Also, you might consider using the toString and fromString functions to work with iCalendar formatted strings, and store that in your MongoDB instance instead of serializing the RRule as JSON.

like image 146
Matt Johnson-Pint Avatar answered Nov 26 '25 09:11

Matt Johnson-Pint



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!