Date objects in rrule options are not converted to local time
See original GitHub issueHi there
I’m running Fullcalendar with the default local
as timezone and I have RRule installed. I create and store RRule strings in my database which I pull back to Fullcalendar to render. Dates are stored as UTC in the database.
When rendering an event using the RRule string like this:
{
id: '2',
title: 'Recurring',
rrule: 'DTSTART:20190801T080000Z\nRRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20190810;BYDAY=MO,TU,WE,TH,FR,SA,SU',
duration: '02:00'
}
The DTSTART
value isn’t converted into local time like it is when you define it as an object like this:
{
id: '2',
title: 'Recurring',
rrule: {
freq: 'weekly',
interval: 1,
byweekday: ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su'],
dtstart: '2019-08-01T08:00:00Z',
until: '2019-08-10'
},
duration: '02:00'
}
If you use RRules rrulestr
function to map the string into an RRule object, you explicitly have to call toISOString()
on dtstart
to make it work.
{
freq: rrule.options.freq,
interval: rrule.options.interval,
byweekday: ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su'],
dtstart: rrule.options.dtstart.toISOString(),
until: rrule.options.until.toISOString()
}
I guess this is expected behaviour due to the datetime format that’s in the RRule string? Is there a better way of dealing with this issue? Can Fullcalendar take care of this for me?
Here’s a sample repo (Angular app) for this: https://github.com/martinsiden/fullcalendar-rrule
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top GitHub Comments
Good news, this only took 6 hours to figure out 😛
Anything that is a recurring definition is exempt for the built-in timezone adjustment. As seen here: https://github.com/fullcalendar/fullcalendar/blob/44c16bb687c911318306f1c1d0e05bfb186cc9a7/packages/core/src/reducers/eventStore.ts#L144-L145
Any plugins that implement a recurring instance register a callback
expand()
that takes 3 params, the third of which is the newDateEnv
. This object contains the new timezone and has methods for converting dates into the requested timezone.You can see here that the third param isn’t being used at all in the rrule plugin: https://github.com/fullcalendar/fullcalendar/blob/44c16bb687c911318306f1c1d0e05bfb186cc9a7/packages/rrule/src/main.ts#L42
If we add that 3rd param we can now add an array map call to convert all the date objects that rrule generates into the requested timezone.
released in v5.2.0!