RRule UNTIL date not being saved correctly with timezone

562 Views Asked by At

I'm using the JS version of the RRule package (akubroztocil/rrule) in VueJS. I've noticed that when creating the RRule string using the toString() method that the UNTIL timestamp does not include the "Z" at the end. I believe this is to incdicate timezone? For example. I parse the UNTIL date into a Date object and then convert it to UTC as below:

let rrule = {};

//this.until = "2021-05-01" for example
const parsedDate = new Date(Date.parse(this.until)); 
const until = new Date(
  Date.UTC(
    parsedDate.getFullYear(),
    parsedDate.getMonth(),
    parsedDate.getDate()
  )
);
this.$set(rrule, "until", until);
this.rule = new RRule(rrule);

I do the exact same above for the DTSTART. If I then run this.rule.toString() method the resulting string is: DTSTART:20210419T000000Z\nRRULE:UNTIL=20210501T000000;FREQ=WEEKLY;BYDAY=MO,FR;INTERVAL=1

Notice how the DTSTART has a "Z" at the end but UNTIL does not. This causes an exception on my Laravel backend where I use the PHP version of the same RRule package. If I manually add the "Z" to the end then it works fine.

The exception from the backend's side:

"Invalid UNTIL property: if the "DTSTART" property is specified as a date with UTC time or a date with local time and time zone reference, then the UNTIL rule part MUST be specified as a date with UTC time."

How can I do it in such a way that I don't manually have to add the "Z" to the end of the UNTIL timestamp?

Below is a similar issue referenced...

Timezone issue with UNTIL in ical RRULE statement

1

There are 1 best solutions below

0
On

I solved this issue by removing a rule I had previously set up on the rule set that I had forgotten about.

this.$set(rule, "tzid", "UTC");

According to this issue: https://github.com/jakubroztocil/rrule/issues/440

"It's only adding the Z if a tzid is not specified"

After explicitly removing the UTC tzid it's generating the RRule string as expected.