section-2
Version:
A library for calculating unsocial hours entitlements under the NHS agenda for change's section 2
13 lines (12 loc) • 558 B
JavaScript
export const makeToAlwaysLater = (from, to, allowEqual = true) => {
const fromObj = convertToDate(from);
const toObj = convertToDate(to);
const fromTime = fromObj.getTime();
const toTime = toObj.getTime();
if (fromTime > toTime || (fromTime === toTime && !allowEqual)) {
toObj.setDate(toObj.getDate() + 1);
}
return { fromObj, toObj };
};
export const convertToDate = (val) => val instanceof Date ? val : new Date(val);
export const convertToNumber = (val) => typeof val === "number" ? val : convertToDate(val).getTime();