diff --git a/lib/workers/branch/schedule.js b/lib/workers/branch/schedule.js index a03a69deff..a210423a02 100644 --- a/lib/workers/branch/schedule.js +++ b/lib/workers/branch/schedule.js @@ -172,6 +172,10 @@ function isScheduledNow(config) { return false; } } + // Check for week of year + if (schedule.wy && !schedule.wy.includes(now.week())) { + return false; + } logger.debug(`Matches schedule ${scheduleText}`); return true; }); diff --git a/test/workers/branch/schedule.spec.js b/test/workers/branch/schedule.spec.js index 602c29fbb7..3026203aeb 100644 --- a/test/workers/branch/schedule.spec.js +++ b/test/workers/branch/schedule.spec.js @@ -202,5 +202,17 @@ describe('workers/branch/schedule', () => { const res = schedule.isScheduledNow(config); expect(res).toBe(true); }); + it('approves valid weeks of year', () => { + config.schedule = ['every 2 weeks of the year before 08:00 on Monday']; + mockDate.set('2017-01-02T06:00:00.000'); // Locally Monday, 2 January 2017 6am (first Monday of the year) + const res = schedule.isScheduledNow(config); + expect(res).toBe(true); + }); + it('rejects on weeks of year', () => { + config.schedule = ['every 2 weeks of the year before 08:00 on Monday']; + mockDate.set('2017-01-09T06:00:00.000'); // Locally Monday, 2 January 2017 6am (second Monday of the year) + const res = schedule.isScheduledNow(config); + expect(res).toBe(false); + }); }); });