How To Produce Recurrence Rschedule Durations With Timeshifts
Solution 1:
Because I'm not familiar with these timezone's (and don't know what timezone the "expected output" is suppose to be in), it's a little unclear what you expect to happen. But as @JorgeFuentesGonzález pointed out in a comment, an issue is probably that you aren't providing the start
datetime in the proper timezone.
As pointed out in the rSchedule source code (which should conveniently show up as a tooltip in editors like VSCode--edit I've gone ahead and clarified this in the rSchedule docs as well), the timezone
config option for Rule
objects does not change the timezone the rule is in, it changes the timezone the rule is displayed in. This distinction is important for the internal functioning of rSchedule, but I can see in this case it is unclear.
So your rule is generating occurrences in your local timezone (because start: moment(Date.UTC(2019, 0, 1))
generates a local moment
), and then those occurrences are being transformed into the 'Europe/Berlin'
timezone before being output. Except wait! That's not what's happening. This Rule
is part of a Schedule
, so it's the schedule's timezone which determines the output timezone of occurrences. The schedule appears to have no timezone (so it is in the local timezone). So I think the rule is in the local timezone, and the output dates are in the local timezone.
- Note: console logging using
toISOString()
may be obfuscating the fact that your output dates are in your local timezone, rather than whatever timezone you expect.
Depending on what you are trying to accomplish, I'd suggest something like the following:
import { Schedule } from"@rschedule/core/generators";
import'@rschedule/moment-tz-date-adapter/setup';
import moment from'moment-timezone';
const schedule = newSchedule({
rrules: [
{
frequency: "MONTHLY",//frequency: "WEEKLY",duration:1000 * 60 * 60 * 3,//input.workingHours[0].end-input.workingHours[0].start,byHourOfDay:[12],//input.workingHours[0].endstart: moment.tz(Date.UTC(2019, 0, 1), 'Europe/Berlin'),
end: moment.tz(Date.UTC(2020, 0, 0), 'Europe/Berlin')
}
],
timezone:'Europe/Berlin'
});
Let me know if you're still not seeing what you expect.
Post a Comment for "How To Produce Recurrence Rschedule Durations With Timeshifts"