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

This commit is contained in:
Alys
2015-11-22 08:38:45 +10:00
parent 2f8b6d68e8
commit a380c1aa30
3 changed files with 20 additions and 27 deletions

View File

@@ -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');
}