Skip to content

Commit

Permalink
fix(core/schedule): accept matching cron schedules when run on Sundays (
Browse files Browse the repository at this point in the history
  • Loading branch information
benj-dobs committed Jan 10, 2023
1 parent 988692a commit 190753a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions lib/workers/repository/update/branch/schedule.spec.ts
Expand Up @@ -239,6 +239,30 @@ describe('workers/repository/update/branch/schedule', () => {
expect(res).toBeFalse();
});

describe('supports cron syntax on Sundays', () => {
beforeEach(() => {
mockDate.set('2023-01-08T10:50:00.000'); // Locally Sunday 8 January 2023 10:50am
});

it('approves if the weekday is *', () => {
config.schedule = ['* * * * *'];
const res = schedule.isScheduledNow(config);
expect(res).toBeTrue();
});

it('approves if the weekday is 0', () => {
config.schedule = ['* * * * 0'];
const res = schedule.isScheduledNow(config);
expect(res).toBeTrue();
});

it('rejects if the weekday is 1', () => {
config.schedule = ['* * * * 1'];
const res = schedule.isScheduledNow(config);
expect(res).toBeFalse();
});
});

describe('supports timezone', () => {
const cases: [string, string, string, boolean][] = [
['after 4pm', 'Asia/Singapore', '2017-06-30T15:59:00.000+0800', false],
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/update/branch/schedule.ts
Expand Up @@ -98,7 +98,7 @@ function cronMatches(cron: string, now: DateTime): boolean {
return false;
}

if (parsedCron.weekDays.indexOf(now.weekday) === -1) {
if (!parsedCron.weekDays.includes(now.weekday % 7)) {
// Weekdays mismatch
return false;
}
Expand Down

0 comments on commit 190753a

Please sign in to comment.