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

77 lines 2.78 kB
import { formatDateToUTC } from './formatDate'; import { transformDate } from './transformDate'; export const isAfter = (date1, date2) => { return formatDateToUTC(date1) > formatDateToUTC(date2); }; export const isBefore = (date1, date2) => { return formatDateToUTC(date1) < formatDateToUTC(date2); }; export const isDatesEqual = (firstDate, secondDate, shouldCompareTime = false) => { const firstDateModified = typeof firstDate === 'string' || typeof firstDate === 'number' ? transformDate(firstDate) : firstDate; const secondDateModified = typeof secondDate === 'string' || typeof secondDate === 'number' ? transformDate(secondDate) : secondDate; if (shouldCompareTime) { return firstDateModified.getTime() === secondDateModified.getTime(); } return (firstDateModified.getDate() === secondDateModified.getDate() && firstDateModified.getMonth() === secondDateModified.getMonth() && firstDateModified.getFullYear() === secondDateModified.getFullYear()); }; export const getAddDays = (date, days) => { const newDate = new Date(date); newDate.setDate(newDate.getDate() + days); return newDate; }; export const getAddMonths = (date, months) => { const newDate = new Date(date); newDate.setMonth(newDate.getMonth() + months); return newDate; }; export const getAddYears = (date, years) => { const newDate = new Date(date); newDate.setFullYear(newDate.getFullYear() + years); return newDate; }; export const getSubDays = (date, days) => { const newDate = new Date(date); newDate.setDate(newDate.getDate() - days); return newDate; }; export const getSubMonths = (date, months) => { const newDate = new Date(date); newDate.setMonth(newDate.getMonth() - months); return newDate; }; export const getSubYears = (date, years) => { const newDate = new Date(date); newDate.setFullYear(newDate.getFullYear() - years); return newDate; }; export 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; }; export 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; }; //# sourceMappingURL=date.js.map