question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Date objects in rrule options are not converted to local time

See original GitHub issue

Hi 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
paco3346commented, Mar 5, 2020

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 new DateEnv. 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.

    expand: function (rrule, framingRange, dateEnv) {
        return rrule.between(framingRange.start, framingRange.end, true)
          .map(function (d){
              return dateEnv.createMarker(d);
          })
          .filter(function (date) {
              return date.valueOf() < framingRange.end.valueOf();
          });
    }
0reactions
arshawcommented, Aug 2, 2020

released in v5.2.0!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I convert date into UTC format from rrule string using ...
On the server I want to use the rrule and the timezone offset to generate a list of dates in UTC format. Here's...
Read more >
rrule — dateutil 2.8.2 documentation - Read the Docs
Recurrence rules may generate recurrence instances with an invalid date (e.g., February 30) or nonexistent local time (e.g., 1:30 AM on a day...
Read more >
Demystifying DateTime Manipulation in JavaScript - Toptal
Converting a string to a JavaScript date object is done in different ways. ... It's not possible to change just the time zone...
Read more >
Working with dates and timezones in JavaScript - Ursa Health
Remember that getTime() converts the date to an integer representing milliseconds. If we back out the server timezone offset, and apply the ...
Read more >
Dates and Times in R - Berkeley Statistics
The general rule for date/time data in R is to use the simplest ... Date function will return a Date object which can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found