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.27k stars 506 forks source link

Wrong result of the between function when machine local timezone greater than GMT+12 #555

Open williamvinogradov opened 1 year ago

williamvinogradov commented 1 year ago

Hello!

There seems to be an issue with rrule 'between' function results when the local timezone is greater than GMT+12 (e.g. Apia Standard Time GMT+13 timezone)

Here is the simple script to reproduce this issue:

import rrule from 'rrule';
const { RRule } = rrule;

const startDate = new Date('2021-03-23T10:00:00Z');
const minDate = new Date('2021-03-20T00:00:00Z');
const maxDate = new Date('2021-03-26T00:00:00Z');

const rule = new RRule({
    freq: RRule.DAILY,
    dtstart: startDate,
});

const result = rule.between(minDate, maxDate, true);
console.log('result: ', result);

With a local machine's time zone GMT+12 (e.g. Fiji Standard Time) the console output is correct:

result:  [
  2021-03-23T10:00:00.000Z,
  2021-03-24T10:00:00.000Z,
  2021-03-25T10:00:00.000Z
]

But, with a local machine's time zone GMT+13 (e.g. Apia Standard Time), the console output is incorrect:

result:  [ 2021-03-24T10:00:00.000Z, 2021-03-25T10:00:00.000Z ]

2021-03-23T10:00:00.000Z is missing here.


Reporting an issue

Thank you for taking an interest in rrule! Please include the following in your report:


Operating system: macOS 12.4 (Monterey) Node: v16.15.1 Timezone: Apia Standart Time RRule version: 2.7.1 (latest)

map-r commented 1 year ago

I've also ran into the same issue. I was using RRule.fromString(rruleInStringFormat) to generate the RRules, but when it comes to obtaining any date with after or between, it starts with a date+1 day (e.g. gives Tuesday where it should give Monday). Funny thing is, that it returns correct hours/minutes, but not the date.

Can it be somehow related to https://github.com/jakubroztocil/rrule/issues/537 (redundant timezone maths)?