UNPKG

@kubit-ui-web/react-components

Version:

Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience

91 lines 3.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllWeekdayNames = exports.getAllMonthNames = exports.getSubYears = exports.getSubMonths = exports.getSubDays = exports.getAddYears = exports.getAddMonths = exports.getAddDays = exports.isDatesEqual = exports.isBefore = exports.isAfter = void 0; const formatDate_1 = require("./formatDate"); const transformDate_1 = require("./transformDate"); const isAfter = (date1, date2) => { return (0, formatDate_1.formatDateToUTC)(date1) > (0, formatDate_1.formatDateToUTC)(date2); }; exports.isAfter = isAfter; const isBefore = (date1, date2) => { return (0, formatDate_1.formatDateToUTC)(date1) < (0, formatDate_1.formatDateToUTC)(date2); }; exports.isBefore = isBefore; const isDatesEqual = (firstDate, secondDate, shouldCompareTime = false) => { const firstDateModified = typeof firstDate === 'string' || typeof firstDate === 'number' ? (0, transformDate_1.transformDate)(firstDate) : firstDate; const secondDateModified = typeof secondDate === 'string' || typeof secondDate === 'number' ? (0, transformDate_1.transformDate)(secondDate) : secondDate; if (shouldCompareTime) { return firstDateModified.getTime() === secondDateModified.getTime(); } return (firstDateModified.getDate() === secondDateModified.getDate() && firstDateModified.getMonth() === secondDateModified.getMonth() && firstDateModified.getFullYear() === secondDateModified.getFullYear()); }; exports.isDatesEqual = isDatesEqual; const getAddDays = (date, days) => { const newDate = new Date(date); newDate.setDate(newDate.getDate() + days); return newDate; }; exports.getAddDays = getAddDays; const getAddMonths = (date, months) => { const newDate = new Date(date); newDate.setMonth(newDate.getMonth() + months); return newDate; }; exports.getAddMonths = getAddMonths; const getAddYears = (date, years) => { const newDate = new Date(date); newDate.setFullYear(newDate.getFullYear() + years); return newDate; }; exports.getAddYears = getAddYears; const getSubDays = (date, days) => { const newDate = new Date(date); newDate.setDate(newDate.getDate() - days); return newDate; }; exports.getSubDays = getSubDays; const getSubMonths = (date, months) => { const newDate = new Date(date); newDate.setMonth(newDate.getMonth() - months); return newDate; }; exports.getSubMonths = getSubMonths; const getSubYears = (date, years) => { const newDate = new Date(date); newDate.setFullYear(newDate.getFullYear() - years); return newDate; }; exports.getSubYears = getSubYears; const getAllMonthNames = (type = 'long') => { const monthNames = []; for (let i = 0; i < 12; i++) { const date = new Date(); date.setDate(1); // stablish the first day of the month date.setMonth(i); const monthName = date.toLocaleString('en-US', { month: type, }); monthNames.push(monthName); } return monthNames; }; exports.getAllMonthNames = getAllMonthNames; const getAllWeekdayNames = (type = 'long', isSundayFirst) => { const weekdayNames = []; for (let i = 0; i < 7; i++) { const date = new Date(0, 0, isSundayFirst ? i : i + 1); const weekdayName = date.toLocaleString('en-US', { weekday: type, }); weekdayNames.push(weekdayName); } return weekdayNames; }; exports.getAllWeekdayNames = getAllWeekdayNames; //# sourceMappingURL=date.js.map