UNPKG

tubular-common

Version:

Tubular Common Models and Data Transformer

25 lines 1.41 kB
import dayjs from 'dayjs'; import customParseFormat from 'dayjs/plugin/customParseFormat'; import isBetween from 'dayjs/plugin/isBetween'; import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'; import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'; dayjs.extend(customParseFormat); dayjs.extend(isSameOrBefore); dayjs.extend(isSameOrAfter); dayjs.extend(isBetween); export const areDatesEqual = (column, date1, date2) => dayjs(date1, column.dateOriginFormat).isSame(dayjs(date2, column.dateOriginFormat), 'd'); export const isDateAfter = (column, date1, date2, inclusive = false) => { if (inclusive) { return dayjs(date1, column.dateOriginFormat).isSameOrAfter(dayjs(date2, column.dateOriginFormat), 'd'); } return dayjs(date1, column.dateOriginFormat).isAfter(dayjs(date2, column.dateOriginFormat), 'd'); }; export const isDateBefore = (column, date1, date2, inclusive = false) => { if (inclusive) { return dayjs(date1, column.dateOriginFormat).isSameOrBefore(dayjs(date2, column.dateOriginFormat), 'd'); } return dayjs(date1, column.dateOriginFormat).isBefore(dayjs(date2, column.dateOriginFormat), 'd'); }; export const dateIsBetween = (column, from, to, value) => dayjs(dayjs(value, column.dateOriginFormat)).isBetween(dayjs(from, column.dateOriginFormat), dayjs(to, column.dateOriginFormat), null, '[]'); export default dayjs; //# sourceMappingURL=dateUtils.js.map