mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
refactor api.startOfWeek to a cron.js function not exposed on api
This commit is contained in:
@@ -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');
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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');
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user