4

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 ?

Kai23
  • 1,556
  • 2
  • 16
  • 30

1 Answers1

1

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.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • Hi, thanks for your answer. Do you think that this is the way to go ? https://gist.github.com/florianchevallier/ff196e25678e0be4d40a4fa06bc10049 And you definitively have a point for the `toString` and `fromString` functions – Kai23 Mar 18 '19 at 21:41