UNPKG

section-2

Version:

A library for calculating unsocial hours entitlements under the NHS agenda for change's section 2

23 lines (22 loc) 972 B
import { convertToNumber } from "./conversions"; import { formatDate } from "./formatDates"; import bankHolidays from "../data/bankHolidays"; export const calculateBreak = (shiftLengthMs, break_override) => break_override === null || break_override === undefined ? shiftLengthMs > 21600000 ? 1800000 : 0 : break_override; export const calculateShiftLength = (from, to) => { return convertToNumber(to) - convertToNumber(from); }; export const calculateShiftHours = (from, to, breakOverrideMs = null) => { const shiftLength = calculateShiftLength(from, to); if (breakOverrideMs === null || breakOverrideMs === undefined) { return shiftLength > 21600000 ? shiftLength - 1800000 : shiftLength; } return Math.max(shiftLength - breakOverrideMs, 0); }; export const isBankHoliday = (date) => { const lookupDate = formatDate(date, "sorting"); return bankHolidays["england-and-wales"].some((bh) => bh === lookupDate); };