mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
refactor api.daysSince to a cron.js function not exposed on api
This commit is contained in:
@@ -47,7 +47,6 @@ export function startOfWeek (options) {
|
||||
return moment(o.now).startOf('week');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
This is designed for use with any date that has an important time portion (e.g., when comparing the current date-time with the previous cron's date-time for determing if cron should run now).
|
||||
It changes the time portion of the date-time to be the Custom Day Start hour, so that the date-time is now the user's correct start of day.
|
||||
@@ -68,3 +67,13 @@ export function startOfDay (options) {
|
||||
return dayStart;
|
||||
}
|
||||
|
||||
/*
|
||||
Absolute diff from "yesterday" till now
|
||||
*/
|
||||
|
||||
export function daysSince (yesterday, options = {}) {
|
||||
let o = sanitizeOptions(options);
|
||||
|
||||
return startOfDay(_.defaults({ now: o.now }, o)).diff(startOfDay(_.defaults({ now: yesterday }, o)), 'days');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user