flowbite-react
Version:
Official React components built for Flowbite and Tailwind CSS
1 lines • 9.69 kB
Source Map (JSON)
{"version":3,"file":"helpers.mjs","sources":["../../../../src/components/Datepicker/helpers.ts"],"sourcesContent":["export enum Views {\n Days = 0,\n Months = 1,\n Years = 2,\n Decades = 3,\n}\n\nexport enum WeekStart {\n Sunday = 0,\n Monday = 1,\n Tuesday = 2,\n Wednesday = 3,\n Thursday = 4,\n Friday = 5,\n Saturday = 6,\n}\n\nexport const isDateInRange = (date: Date, minDate?: Date, maxDate?: Date): boolean => {\n const dateTime = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();\n\n if (minDate && maxDate) {\n const minDateTime = new Date(minDate.getFullYear(), minDate.getMonth(), minDate.getDate()).getTime();\n const maxDateTime = new Date(maxDate.getFullYear(), maxDate.getMonth(), maxDate.getDate()).getTime();\n return dateTime >= minDateTime && dateTime <= maxDateTime;\n }\n\n if (minDate) {\n const minDateTime = new Date(minDate.getFullYear(), minDate.getMonth(), minDate.getDate()).getTime();\n return dateTime >= minDateTime;\n }\n\n if (maxDate) {\n const maxDateTime = new Date(maxDate.getFullYear(), maxDate.getMonth(), maxDate.getDate()).getTime();\n return dateTime <= maxDateTime;\n }\n\n return true;\n};\n\nexport const isDateEqual = (date: Date, selectedDate: Date): boolean => {\n date = new Date(date.getFullYear(), date.getMonth(), date.getDate());\n selectedDate = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate());\n\n return date.getTime() === selectedDate.getTime();\n};\n\nexport const getFirstDateInRange = (date: Date, minDate?: Date, maxDate?: Date): Date => {\n if (!isDateInRange(date, minDate, maxDate)) {\n if (minDate && date < minDate) {\n date = minDate;\n } else if (maxDate && date > maxDate) {\n date = maxDate;\n }\n }\n return date;\n};\n\nexport const getFirstDayOfTheMonth = (date: Date, weekStart: WeekStart): Date => {\n const firstDayOfMonth = new Date(date.getFullYear(), date.getMonth(), 1);\n const dayOfWeek = firstDayOfMonth.getDay();\n\n let diff = dayOfWeek - weekStart;\n if (diff < 0) {\n diff += 7;\n }\n\n return addDays(firstDayOfMonth, -diff);\n};\n\nexport const getWeekDays = (lang: string, weekStart: WeekStart): string[] => {\n const weekdays: string[] = [];\n const date = new Date(0);\n date.setDate(date.getDate() - date.getDay() + weekStart);\n\n const formatter = new Intl.DateTimeFormat(lang, { weekday: \"short\" });\n\n for (let i = 0; i < 7; i++) {\n weekdays.push(formatter.format(addDays(date, i)));\n }\n\n return weekdays;\n};\n\nexport const addDays = (date: Date, amount: number): Date => {\n const newDate = new Date(date);\n newDate.setDate(newDate.getDate() + amount);\n return newDate;\n};\n\nexport const addMonths = (date: Date, amount: number): Date => {\n const newDate = new Date(date);\n newDate.setMonth(newDate.getMonth() + amount);\n return newDate;\n};\n\nexport const addYears = (date: Date, amount: number): Date => {\n const newDate = new Date(date);\n newDate.setFullYear(newDate.getFullYear() + amount);\n return newDate;\n};\n\nexport const getFormattedDate = (language: string, date: Date, options?: Intl.DateTimeFormatOptions): string => {\n let defaultOptions: Intl.DateTimeFormatOptions = {\n day: \"numeric\",\n month: \"long\",\n year: \"numeric\",\n };\n\n if (options) {\n defaultOptions = options;\n }\n\n return new Intl.DateTimeFormat(language, defaultOptions).format(date);\n};\n\nexport const startOfYearPeriod = (date: Date, years: number): number => {\n const year = date.getFullYear();\n return Math.floor(year / years) * years;\n};\n\nexport const isDateInDecade = (date: Date, startYear: number): boolean => {\n const year = date.getFullYear();\n const endYear = startYear + 9;\n return year >= startYear && year <= endYear;\n};\n\nexport const isDateRangeInDecade = (\n startDate: Date,\n endDate: Date,\n decadeStart: number,\n decadeEnd: number,\n): boolean => {\n const startYear = startDate.getFullYear();\n const endYear = endDate.getFullYear();\n\n if (decadeStart && decadeEnd) {\n // Check if the start and end years of the date range are within the decade\n const isStartYearInRange = isDateInRange(\n new Date(startYear, 0, 1),\n new Date(decadeStart, 0, 1),\n new Date(decadeEnd, 11, 31),\n );\n const isEndYearInRange = isDateInRange(\n new Date(endYear, 11, 31),\n new Date(decadeStart, 0, 1),\n new Date(decadeEnd, 11, 31),\n );\n\n return isStartYearInRange && isEndYearInRange;\n }\n\n // If decadeStart or decadeEnd is not provided, treat it as an open-ended range\n return true;\n};\n"],"names":[],"mappings":"AACU,IAAC,KAAK,mBAAmB,CAAC,CAAC,MAAM,KAAK;AAChD,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;AACtC,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;AAC1C,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;AACxC,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;AAC5C,EAAE,OAAO,MAAM,CAAC;AAChB,CAAC,EAAE,KAAK,IAAI,EAAE,EAAE;AACN,IAAC,SAAS,mBAAmB,CAAC,CAAC,UAAU,KAAK;AACxD,EAAE,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;AAClD,EAAE,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;AAClD,EAAE,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;AACpD,EAAE,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;AACxD,EAAE,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC;AACtD,EAAE,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;AAClD,EAAE,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG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