mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +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,
|
||||
};
|
||||
}
|
||||
|
||||
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) {
|
||||
var dayStart, o;
|
||||
if (options == null) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user