From 6183fd9e7142ea29b4c95b347deb630f6296613b Mon Sep 17 00:00:00 2001 From: Alys Date: Sat, 21 Nov 2015 22:26:05 +1000 Subject: [PATCH] refactor api.startOfWeek to a cron.js function not exposed on api --- common/script/cron.js | 10 ++++++++++ common/script/index.js | 9 --------- test/common/algos.mocha.js | 5 +++-- test/common/dailies.js | 5 ++++- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/common/script/cron.js b/common/script/cron.js index 797adff67a..dba2a13717 100644 --- a/common/script/cron.js +++ b/common/script/cron.js @@ -37,3 +37,13 @@ export function sanitizeOptions (o) { now, }; } + +export function startOfWeek (options) { + if (options === null) { + options = {}; + } + let o = sanitizeOptions(options); + + return moment(o.now).startOf('week'); +} + diff --git a/common/script/index.js b/common/script/index.js index 2260195328..7d012165f4 100644 --- a/common/script/index.js +++ b/common/script/index.js @@ -73,15 +73,6 @@ api.planGemLimits = { ------------------------------------------------------ */ -api.startOfWeek = api.startOfWeek = function(options) { - var o; - if (options == null) { - options = {}; - } - o = sanitizeOptions(options); - return moment(o.now).startOf('week'); -}; - api.startOfDay = function(options) { var dayStart, o; if (options == null) { diff --git a/test/common/algos.mocha.js b/test/common/algos.mocha.js index c10e18c6d7..a57a049233 100644 --- a/test/common/algos.mocha.js +++ b/test/common/algos.mocha.js @@ -1,6 +1,7 @@ /* eslint-disable camelcase, func-names, no-shadow */ import { DAY_MAPPING, + startOfWeek, } from '../../common/script/cron'; let expect = require('expect.js'); @@ -209,7 +210,7 @@ let repeatWithoutLastWeekday = () => { s: true, }; - if (shared.startOfWeek(moment().zone(0)).isoWeekday() === 1) { + if (startOfWeek(moment().zone(0)).isoWeekday() === 1) { repeat.su = false; } else { repeat.s = false; @@ -1270,7 +1271,7 @@ describe('Cron', () => { function runCron (options) { _.each([480, 240, 0, -120], function (timezoneOffset) { - let now = shared.startOfWeek({ + let now = startOfWeek({ timezoneOffset, }).add(options.currentHour || 0, 'hours'); diff --git a/test/common/dailies.js b/test/common/dailies.js index d9c1621904..079ecb59e9 100644 --- a/test/common/dailies.js +++ b/test/common/dailies.js @@ -1,4 +1,7 @@ /* eslint-disable camelcase */ +import { + startOfWeek, +} from '../../common/script/cron'; let expect = require('expect.js'); // eslint-disable-line no-shadow let moment = require('moment'); @@ -17,7 +20,7 @@ let repeatWithoutLastWeekday = () => { // eslint-disable-line no-unused-vars s: true, }; - if (shared.startOfWeek(moment().zone(0)).isoWeekday() === 1) { + if (startOfWeek(moment().zone(0)).isoWeekday() === 1) { repeat.su = false; } else { repeat.s = false;