UNPKG

ngx-bootstrap

Version:
50 lines 1.76 kB
import { endOf, startOf } from './start-end-of'; export function isAfter(date1, date2, units) { if (units === void 0) { units = 'milliseconds'; } if (!date1 || !date2) { return false; } if (units === 'milliseconds') { return date1.valueOf() > date2.valueOf(); } return date2.valueOf() < startOf(date1, units).valueOf(); } export function isBefore(date1, date2, units) { if (units === void 0) { units = 'milliseconds'; } if (!date1 || !date2) { return false; } if (units === 'milliseconds') { return date1.valueOf() < date2.valueOf(); } return endOf(date1, units).valueOf() < date2.valueOf(); } export function isBetween(date, from, to, units, inclusivity) { if (inclusivity === void 0) { inclusivity = '()'; } var leftBound = inclusivity[0] === '(' ? isAfter(date, from, units) : !isBefore(date, from, units); var rightBound = inclusivity[1] === ')' ? isBefore(date, to, units) : !isAfter(date, to, units); return leftBound && rightBound; } export function isSame(date1, date2, units) { if (units === void 0) { units = 'milliseconds'; } if (!date1 || !date2) { return false; } if (units === 'milliseconds') { return date1.valueOf() === date2.valueOf(); } var inputMs = date2.valueOf(); return (startOf(date1, units).valueOf() <= inputMs && inputMs <= endOf(date1, units).valueOf()); } export function isSameOrAfter(date1, date2, units) { return isSame(date1, date2, units) || isAfter(date1, date2, units); } export function isSameOrBefore(date1, date2, units) { return isSame(date1, date2, units) || isBefore(date1, date2, units); } //# sourceMappingURL=date-compare.js.map