refactor api.startOfWeek to a cron.js function not exposed on api

This commit is contained in:
Alys
2015-11-21 22:26:05 +10:00
parent e0784a9791
commit 6183fd9e71
4 changed files with 17 additions and 12 deletions

View File

@@ -37,3 +37,13 @@ export function sanitizeOptions (o) {
now, now,
}; };
} }
export function startOfWeek (options) {
if (options === null) {
options = {};
}
let o = sanitizeOptions(options);
return moment(o.now).startOf('week');
}

View File

@@ -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) { api.startOfDay = function(options) {
var dayStart, o; var dayStart, o;
if (options == null) { if (options == null) {

View File

@@ -1,6 +1,7 @@
/* eslint-disable camelcase, func-names, no-shadow */ /* eslint-disable camelcase, func-names, no-shadow */
import { import {
DAY_MAPPING, DAY_MAPPING,
startOfWeek,
} from '../../common/script/cron'; } from '../../common/script/cron';
let expect = require('expect.js'); let expect = require('expect.js');
@@ -209,7 +210,7 @@ let repeatWithoutLastWeekday = () => {
s: true, s: true,
}; };
if (shared.startOfWeek(moment().zone(0)).isoWeekday() === 1) { if (startOfWeek(moment().zone(0)).isoWeekday() === 1) {
repeat.su = false; repeat.su = false;
} else { } else {
repeat.s = false; repeat.s = false;
@@ -1270,7 +1271,7 @@ describe('Cron', () => {
function runCron (options) { function runCron (options) {
_.each([480, 240, 0, -120], function (timezoneOffset) { _.each([480, 240, 0, -120], function (timezoneOffset) {
let now = shared.startOfWeek({ let now = startOfWeek({
timezoneOffset, timezoneOffset,
}).add(options.currentHour || 0, 'hours'); }).add(options.currentHour || 0, 'hours');

View File

@@ -1,4 +1,7 @@
/* eslint-disable camelcase */ /* eslint-disable camelcase */
import {
startOfWeek,
} from '../../common/script/cron';
let expect = require('expect.js'); // eslint-disable-line no-shadow let expect = require('expect.js'); // eslint-disable-line no-shadow
let moment = require('moment'); let moment = require('moment');
@@ -17,7 +20,7 @@ let repeatWithoutLastWeekday = () => { // eslint-disable-line no-unused-vars
s: true, s: true,
}; };
if (shared.startOfWeek(moment().zone(0)).isoWeekday() === 1) { if (startOfWeek(moment().zone(0)).isoWeekday() === 1) {
repeat.su = false; repeat.su = false;
} else { } else {
repeat.s = false; repeat.s = false;