Search code examples
javascriptrecurrencerrule

rruleJS: Consideration of timezone for weekly case


I'm using rruleJS (https://github.com/jkbrzt/rrule) and have the start date like this:

Start date and time: 2015-09-15 23:45 Every 3rd Week On the week days: Monday, Wednesday, Sunday

I save it and get this rrule:

FREQ=WEEKLY;INTERVAL=3;DTSTART=20150915T234500Z;BYDAY=MO,WE,SU

I would now expect the start time of my recurrence to be at 23:45,

Wed Sep 16 2015 23:45:00 GMT+0200 (CEST), 
Sun Sep 20 2015 23:45:00 GMT+0200 (CEST), 
Mon Oct 05 2015 23:45:00 GMT+0200 (CEST), 
Wed Oct 07 2015 23:45:00 GMT+0200 (CEST), 

...

but instead I get these recurrences:

Wed Sep 16 2015 01:45:00 GMT+0200 (CEST), 
Sun Sep 20 2015 01:45:00 GMT+0200 (CEST), 
Mon Oct 05 2015 01:45:00 GMT+0200 (CEST), 
Wed Oct 07 2015 01:45:00 GMT+0200 (CEST), 
Sun Oct 11 2015 01:45:00 GMT+0200 (CEST), 
....

It's because of the conversion to local time (CEST-> +2 hours -> 23:45 becomes 01:45). I can subtract the timezone offset but this would switch to another weekday. For example if I'd subtract 2 hours form Wed Sep 16 2015 01:45:00 GMT+0200 (CEST), I'd get Tue Sep 15 2015 23:45:00 GMT+0200 (CEST).

But that's not what I want: The time would be correct but not the weekday. I don't want it to recur on Tuesday but on Monday, Wednesday, or Sunday.

How can I take the timezone into consideration but still keep the starting weekdays?


Solution

  • First of all, does your RRULE really look like

    FREQ=WEEKLY;INTERVAL=3;DTSTART=20150915T234500Z;BYDAY=MO,WE,SU
    

    ?

    The DTSTART is a property, not a parameter of the RRULE.

    Then for your DTSTART, what you want to use is a local time with timezone reference (FORM #3 from https://www.rfc-editor.org/rfc/rfc5545#section-3.3.5 )

    So you want something like:

    DTSTART;TZID=Europe/Berlin:20150915T234500
    RRULE:FREQ=WEEKLY;INTERVAL=3;BYDAY=MO,WE,SU