jkbrzt / rrule

JavaScript library for working with recurrence rules for calendar dates as defined in the iCalendar RFC and more.
https://jkbrzt.github.io/rrule
Other
3.24k stars 506 forks source link

possible issue, skipping initial date when tzid and dtstart is provided #625

Open itai-sagi opened 1 month ago

itai-sagi commented 1 month ago

Reporting an issue

Hi, I have tried switching from UTC based RRule interval generation to a timezone based as it handles some edge cases, however, while doing the move, I noticed that the first time interval is different.

import {Frequency, RRule, Options} from "rrule";

process.env.TZ = 'UTC';

const toDate = `2024-05-14 06:59:59.999+00`; // corresponds with end-of-day in America/Los_Angeles timezone

const frequencyRuleWithTz: Options = {
    tzid: 'America/Los_Angeles',
    byhour: 5,
    count: 1,
    dtstart: new Date(toDate),
    freq: Frequency.DAILY,
} as any;

const frequencyRuleOld: Options = {
    tzid: 'UTC',
    byhour: 12,
    count: 1,
    dtstart: new Date(toDate),
    freq: Frequency.DAILY,
} as any;

let rrule = new RRule(frequencyRuleWithTz as any);

for (const date of rrule.all()) {
    console.log("America/Los_Angeles");
    console.log(date.toISOString());
}

rrule = new RRule(frequencyRuleOld as any);

for (const date of rrule.all()) {
    console.log("UTC");
    console.log(date.toISOString());
}

Output:

America/Los_Angeles
2024-05-15T12:00:00.999Z

UTC
2024-05-14T12:00:00.999Z

the reason why I expected it would be a seemless migration is because UTC 12 PM <=> LA 5 AM (excluding daylight savings), but instead, the 1st iteration is a day after.

this is the value I expected while providing frequencyRuleWithTz

2024-05-14T12:00:00.999Z

I am not sure if that's the expected behavior, but on this case - it does seem like a bug.