Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix next CRON trigger calculation offset #6242

Merged
merged 1 commit into from
Jan 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions app/scripts/modules/core/src/pipeline/triggers/NextRunTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,13 @@ export class NextRunTag extends React.Component<INextRunTagProps, INextRunTagSta
) as ICronTrigger[];
const nextTimes: number[] = [];
crons.forEach(cron => {
const parts = cron.cronExpression.split(' ');
const hours = parts[2];
if (!isNaN(parseInt(hours, 10))) {
const allHours = hours.split('/');
const tz = SETTINGS.defaultTimeZone;
let offset = moment.tz.zone(tz).offset(Date.now());
if (offset) {
offset /= 60;
const start = parseInt(allHours[0], 10);
allHours[0] = ((start + offset) % 24).toString();
parts[2] = allHours.join('/');
}
}
const schedule = later.parse.cron(parts.join(' '), true);
const nextRun = later.schedule(schedule).next(1);
const timezoneOffsetInMs = moment.tz.zone(SETTINGS.defaultTimeZone).offset(Date.now()) * 60 * 1000;
const nextRun = later
.schedule(later.parse.cron(cron.cronExpression, true))
.next(1, new Date(Date.now() - timezoneOffsetInMs));

if (nextRun) {
nextTimes.push(
later
.schedule(schedule)
.next(1)
.getTime(),
);
nextTimes.push(nextRun.getTime() + timezoneOffsetInMs);
}
});
if (nextTimes.length) {
Expand Down