From f5821815041255f8ce51e816cec47a96949167eb Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@keylocation.sg> Date: Wed, 25 Oct 2017 11:37:05 +0200 Subject: [PATCH] fix: check day of month in schedule (#1048) Fixes #1047 --- lib/workers/branch/schedule.js | 8 ++++++++ test/workers/branch/schedule.spec.js | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/workers/branch/schedule.js b/lib/workers/branch/schedule.js index b41d8d7df7..61b207d270 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 502854b69f..e82a981bfb 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); + }); }); }); -- GitLab