diff --git a/lib/workers/branch/schedule.js b/lib/workers/branch/schedule.js index b41d8d7df70f4578dd26bd02621fd83120acee1d..61b207d270f900e9fddd985303c8b0753048a6f3 100644 --- a/lib/workers/branch/schedule.js +++ b/lib/workers/branch/schedule.js @@ -114,6 +114,14 @@ function isScheduledNow(config) { return false; } } + if (schedule.D) { + logger.debug({ schedule_D: schedule.D }, `schedule.D`); + // moment outputs as string but later outputs as integer + const currentDayOfMonth = parseInt(now.format('D'), 10); + if (!schedule.D.includes(currentDayOfMonth)) { + return false; + } + } // Check for start time if (schedule.t_a) { const startSeconds = schedule.t_a[0]; diff --git a/test/workers/branch/schedule.spec.js b/test/workers/branch/schedule.spec.js index 502854b69f5688795b4074b8bf1f8756746a92ed..e82a981bfba99cdc04ee78715647f19974958a6d 100644 --- a/test/workers/branch/schedule.spec.js +++ b/test/workers/branch/schedule.spec.js @@ -162,5 +162,16 @@ describe('workers/branch/schedule', () => { const res = schedule.isScheduledNow(config); expect(res).toBe(true); }); + it('rejects first day of the month', () => { + config.schedule = ['before 11am on the first day of the month']; + const res = schedule.isScheduledNow(config); + expect(res).toBe(false); + }); + it('approves first day of the month', () => { + config.schedule = ['before 11am on the first day of the month']; + mockDate.set(1506835566000); // Sunday, 1 October 2017 05:26:06 + const res = schedule.isScheduledNow(config); + expect(res).toBe(true); + }); }); });