"Error: Attempted to compare a datetime to another date in a different timezone" at OCCURENCES with start/end dates when COUNT option is used in schedule.
Using moment-timezone lib, with moment-timezone adaptor, the method occurrences
breaks when using COUNT option on schedule creation.
This code breaks at ocurrences()
:
const schedule = new Schedule({
rrules: [
{
frequency: "WEEKLY",
interval: 1,
start: moment.tz("2023-02-23T20:00:00.000Z", "America/Sao_Paulo"),
count: 3, // Without COUNT, it should work fine as expected
byDayOfWeek: ["MO"],
},
],
});
const options = {
start: moment.tz("2023-02-18T00:00:00.000Z", "America/Sao_Paulo"),
end: moment.tz("2023-03-30T00:00:00.000Z", "America/Sao_Paulo"),
};
const dates = schedule.occurrences(options).toArray(); // ERROR HERE
return dates;
Error: Attempted to compare a datetime to another date in a different timezone:
{"timezone":"America/Sao_Paulo",
"year":2023,"month":2,"day":27,
"hour":17,"minute":0,"second":0,"millisecond":0}
and
{"timezone":null,
"year":2023,"month":2,"day":18,
"hour":0,"minute":0,"second":0,"millisecond":0}
at new InvalidDateTimeError (<mydir>functions\node_modules\@rschedule\core\umd\main.js:258:41)\n at assertSameTimeZone (<mydir>functions\node_modules\@rschedule\core\umd\main.js:583:13)\n at DateTime.isBefore (<mydir>functions\node_modules\@rschedule\core\umd\main.js:336:7)\n at RecurrenceRulesIterator.<anonymous> (<mydir>functions\node_modules\@rschedule\core\umd\main.js:1105:22)\n at step (<mydir>functions\node_modules\@rschedule\core\umd\main.js:147:21)\n at Object.next (<mydir>functions\node_modules\@rschedule\core\umd\main.js:84:16)\n at RecurrenceRulesIterator.next (<mydir>functions\node_modules\@rschedule\core\umd\main.js:1034:28)\n at Rule.<anonymous> (<mydir>functions\node_modules\@rschedule\core\umd\generators.js:2142:29)\n at step (<mydir>functions\node_modules\@rschedule\core\umd\generators.js:147:21)\n at Object.next (<mydir>functions\node_modules\@rschedule\core\umd\generators.js:84:16)