@zag-js/date-utils 0.52.0 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,747 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var src_exports={};__export(src_exports,{alignCenter:()=>alignCenter,alignDate:()=>alignDate,alignEnd:()=>alignEnd,alignStart:()=>alignStart,alignStartDate:()=>alignStartDate,constrainStart:()=>constrainStart,constrainValue:()=>constrainValue,formatRange:()=>formatRange,formatSelectedDate:()=>formatSelectedDate,formatVisibleRange:()=>formatVisibleRange,getAdjustedDateFn:()=>getAdjustedDateFn,getCustomWeeksInMonth:()=>getCustomWeeksInMonth,getDateRangePreset:()=>getDateRangePreset,getDayFormatter:()=>getDayFormatter,getDaysInWeek:()=>getDaysInWeek,getDecadeRange:()=>getDecadeRange,getEndDate:()=>getEndDate,getMonthDays:()=>getMonthDays,getMonthFormatter:()=>getMonthFormatter,getMonthNames:()=>getMonthNames,getNextDay:()=>getNextDay,getNextPage:()=>getNextPage,getNextRow:()=>getNextRow,getNextSection:()=>getNextSection,getPreviousAvailableDate:()=>getPreviousAvailableDate,getPreviousDay:()=>getPreviousDay,getPreviousPage:()=>getPreviousPage,getPreviousRow:()=>getPreviousRow,getPreviousSection:()=>getPreviousSection,getSectionEnd:()=>getSectionEnd,getSectionStart:()=>getSectionStart,getTodayDate:()=>getTodayDate,getUnitDuration:()=>getUnitDuration,getWeekDays:()=>getWeekDays,getWeekdayFormats:()=>getWeekdayFormats,getYearsRange:()=>getYearsRange,isDateDisabled:()=>isDateDisabled,isDateEqual:()=>isDateEqual,isDateInvalid:()=>isDateInvalid,isDateOutsideVisibleRange:()=>isDateOutsideVisibleRange,isDateUnavailable:()=>isDateUnavailable,isNextVisibleRangeInvalid:()=>isNextVisibleRangeInvalid,isPreviousVisibleRangeInvalid:()=>isPreviousVisibleRangeInvalid,isTodayDate:()=>isTodayDate,parseDateString:()=>parseDateString,setCalendar:()=>setCalendar,setDate:()=>setDate,setMonth:()=>setMonth,setYear:()=>setYear});module.exports=__toCommonJS(src_exports);var import_date=require("@internationalized/date");function alignCenter(date,duration,locale,min,max){let halfDuration={};for(let key in duration){halfDuration[key]=Math.floor(duration[key]/2);if(halfDuration[key]>0&&duration[key]%2===0){halfDuration[key]--}}let aligned=alignStart(date,duration,locale).subtract(halfDuration);return constrainStart(date,aligned,duration,locale,min,max)}function alignStart(date,duration,locale,min,max){let aligned=date;if(duration.years){aligned=(0,import_date.startOfYear)(date)}else if(duration.months){aligned=(0,import_date.startOfMonth)(date)}else if(duration.weeks){aligned=(0,import_date.startOfWeek)(date,locale)}return constrainStart(date,aligned,duration,locale,min,max)}function alignEnd(date,duration,locale,min,max){let d={...duration};if(d.days){d.days--}else if(d.weeks){d.weeks--}else if(d.months){d.months--}else if(d.years){d.years--}let aligned=alignStart(date,duration,locale).subtract(d);return constrainStart(date,aligned,duration,locale,min,max)}function constrainStart(date,aligned,duration,locale,min,max){if(min&&date.compare(min)>=0){aligned=(0,import_date.maxDate)(aligned,alignStart((0,import_date.toCalendarDate)(min),duration,locale))}if(max&&date.compare(max)<=0){aligned=(0,import_date.minDate)(aligned,alignEnd((0,import_date.toCalendarDate)(max),duration,locale))}return aligned}function constrainValue(date,minValue,maxValue){if(minValue){date=(0,import_date.maxDate)(date,(0,import_date.toCalendarDate)(minValue))}if(maxValue){date=(0,import_date.minDate)(date,(0,import_date.toCalendarDate)(maxValue))}return date}function alignDate(date,alignment,duration,locale,min,max){switch(alignment){case"start":return alignStart(date,duration,locale,min,max);case"end":return alignEnd(date,duration,locale,min,max);case"center":default:return alignCenter(date,duration,locale,min,max)}}function alignStartDate(date,startDate,endDate,duration,locale,min,max){if(date.compare(startDate)<0){return alignEnd(date,duration,locale,min,max)}if(date.compare(endDate)>0){return alignStart(date,duration,locale,min,max)}return startDate}var import_date2=require("@internationalized/date");function isTodayDate(date,timeZone){return(0,import_date2.isToday)(date,timeZone)}function isDateEqual(dateA,dateB){return dateB!=null&&(0,import_date2.isSameDay)(dateA,dateB)}function isDateInvalid(date,minValue,maxValue){return minValue!=null&&date.compare(minValue)<0||maxValue!=null&&date.compare(maxValue)>0}function isDateDisabled(date,startDate,endDate,minValue,maxValue){return isDateOutsideVisibleRange(date,startDate,endDate)||isDateInvalid(date,minValue,maxValue)}function isDateUnavailable(date,isUnavailable,locale,minValue,maxValue){if(!date){return false}if(isUnavailable?.(date,locale)){return true}return isDateInvalid(date,minValue,maxValue)}function isDateOutsideVisibleRange(date,startDate,endDate){return date.compare(startDate)<0||date.compare(endDate)>0}function isPreviousVisibleRangeInvalid(startDate,minValue,maxValue){const prevDate=startDate.subtract({days:1});return(0,import_date2.isSameDay)(prevDate,startDate)||isDateInvalid(prevDate,minValue,maxValue)}function isNextVisibleRangeInvalid(endDate,minValue,maxValue){const nextDate=endDate.add({days:1});return(0,import_date2.isSameDay)(nextDate,endDate)||isDateInvalid(nextDate,minValue,maxValue)}function getUnitDuration(duration){let d={...duration};for(let key in d){d[key]=1}return d}function getEndDate(startDate,duration){let d={...duration};if(d.days){d.days--}else{d.days=-1}return startDate.add(d)}function formatRange(startDate,endDate,formatter,toString,timeZone){let parts=formatter.formatRangeToParts(startDate.toDate(timeZone),endDate.toDate(timeZone));let separatorIndex=-1;for(let i=0;i<parts.length;i++){let part=parts[i];if(part.source==="shared"&&part.type==="literal"){separatorIndex=i}else if(part.source==="endRange"){break}}let start="";let end="";for(let i=0;i<parts.length;i++){if(i<separatorIndex){start+=parts[i].value}else if(i>separatorIndex){end+=parts[i].value}}return toString(start,end)}var import_date4=require("@internationalized/date");var import_date3=require("@internationalized/date");function getEraFormat(date){return date?.calendar.identifier==="gregory"&&date.era==="BC"?"short":void 0}function getDayFormatter(locale,timeZone){const date=(0,import_date3.toCalendarDateTime)((0,import_date3.today)(timeZone));return new import_date3.DateFormatter(locale,{weekday:"long",month:"long",year:"numeric",day:"numeric",era:getEraFormat(date),timeZone})}function formatSelectedDate(startDate,endDate,locale,timeZone){let start=startDate;let end=endDate??startDate;let formatter=getDayFormatter(locale,timeZone);if((0,import_date4.isSameDay)(start,end)){return formatter.format(start.toDate(timeZone))}return formatRange(start,end,formatter,(start2,end2)=>`${start2} \u2013 ${end2}`,timeZone)}var import_date6=require("@internationalized/date");var import_date5=require("@internationalized/date");function getMonthFormatter(locale,timeZone){const date=(0,import_date5.toCalendarDate)((0,import_date5.today)(timeZone));return new import_date5.DateFormatter(locale,{month:"long",year:"numeric",era:getEraFormat(date),calendar:date?.calendar.identifier,timeZone})}function formatVisibleRange(startDate,endDate,locale,timeZone){const start=startDate;const end=endDate??startDate;const dayFormatter=getDayFormatter(locale,timeZone);if(!(0,import_date6.isSameDay)(start,(0,import_date6.startOfMonth)(start))){return dayFormatter.formatRange(start.toDate(timeZone),end.toDate(timeZone))}const monthFormatter=getMonthFormatter(locale,timeZone);if((0,import_date6.isSameDay)(end,(0,import_date6.endOfMonth)(start))){return monthFormatter.format(start.toDate(timeZone))}if((0,import_date6.isSameDay)(end,(0,import_date6.endOfMonth)(end))){return monthFormatter.formatRange(start.toDate(timeZone),end.toDate(timeZone))}return""}function getDecadeRange(year){const computedYear=year-year%10-1;const years=[];for(let i=0;i<12;i+=1){const value=computedYear+i;years.push(value)}return years}var import_date8=require("@internationalized/date");var import_date7=require("@internationalized/date");function getStartOfWeek(date,locale,firstDayOfWeek=0){const day=(0,import_date7.getDayOfWeek)(date,locale);const diff=(day-firstDayOfWeek+7)%7;return date.subtract({days:diff})}function getDaysInWeek(weekIndex,from,locale,firstDayOfWeek){const weekDate=from.add({weeks:weekIndex});const dates=[];let date=getStartOfWeek(weekDate,locale,firstDayOfWeek);while(dates.length<7){dates.push(date);let nextDate=date.add({days:1});if((0,import_date8.isSameDay)(date,nextDate)){break}date=nextDate}return dates}function getCustomWeeksInMonth(from,locale,firstDayOfWeek){if(firstDayOfWeek==null){return(0,import_date8.getWeeksInMonth)(from,locale)}const paddingDays=((0,import_date8.getDayOfWeek)((0,import_date8.startOfMonth)(from),locale)-firstDayOfWeek+7)%7;return Math.ceil((paddingDays+from.calendar.getDaysInMonth(from))/7)}function getMonthDays(from,locale,numOfWeeks,firstDayOfWeek){const monthWeeks=numOfWeeks??getCustomWeeksInMonth(from,locale,firstDayOfWeek);const weeks=[...new Array(monthWeeks).keys()];return weeks.map(week=>getDaysInWeek(week,from,locale,firstDayOfWeek))}function getMonthNames(locale,format="long"){const date=new Date(2021,0,1);const monthNames=[];for(let i=0;i<12;i++){monthNames.push(date.toLocaleString(locale,{month:format}));date.setMonth(date.getMonth()+1)}return monthNames}var import_date9=require("@internationalized/date");function getWeekdayFormats(locale,timeZone){const longFormat=new import_date9.DateFormatter(locale,{weekday:"long",timeZone});const shortFormat=new import_date9.DateFormatter(locale,{weekday:"short",timeZone});const narrowFormat=new import_date9.DateFormatter(locale,{weekday:"narrow",timeZone});return value=>{const date=value instanceof Date?value:value.toDate(timeZone);return{value,short:shortFormat.format(date),long:longFormat.format(date),narrow:narrowFormat.format(date)}}}function getWeekDays(date,startOfWeekProp,timeZone,locale){const firstDayOfWeek=getStartOfWeek(date,locale,startOfWeekProp);const weeks=[...new Array(7).keys()];const format=getWeekdayFormats(locale,timeZone);return weeks.map(index=>format(firstDayOfWeek.add({days:index})))}function getYearsRange(range){const years=[];for(let year=range.from;year<=range.to;year+=1){years.push(year)}return years}var import_date10=require("@internationalized/date");function getTodayDate(timeZone){return(0,import_date10.today)(timeZone??(0,import_date10.getLocalTimeZone)())}function getNextDay(date){return date.add({days:1})}function getPreviousDay(date){return date.subtract({days:1})}function setMonth(date,month){return date.set({month})}function setYear(date,year){return date.set({year})}function setCalendar(date,calendar){return(0,import_date10.toCalendar)((0,import_date10.toCalendarDateTime)(date),calendar)}function setDate(date,startDate,isDateUnavailable2,locale,minValue,maxValue){let result;result=constrainValue(date,minValue,maxValue);result=getPreviousAvailableDate(date,startDate,locale,isDateUnavailable2);return result}function getPreviousAvailableDate(date,minValue,locale,isDateUnavailable2){if(!isDateUnavailable2){return date}while(date.compare(minValue)>=0&&isDateUnavailable2(date,locale)){date=date.subtract({days:1})}if(date.compare(minValue)>=0){return date}}var import_date11=require("@internationalized/date");function getAdjustedDateFn(visibleDuration,locale,minValue,maxValue){return function getDate(options){const{startDate,focusedDate}=options;const endDate=getEndDate(startDate,visibleDuration);if(isDateInvalid(focusedDate,minValue,maxValue)){return{startDate,focusedDate:constrainValue(focusedDate,minValue,maxValue),endDate}}if(focusedDate.compare(startDate)<0){return{startDate:alignEnd(focusedDate,visibleDuration,locale,minValue,maxValue),focusedDate:constrainValue(focusedDate,minValue,maxValue),endDate}}if(focusedDate.compare(endDate)>0){return{startDate:alignStart(focusedDate,visibleDuration,locale,minValue,maxValue),endDate,focusedDate:constrainValue(focusedDate,minValue,maxValue)}}return{startDate,endDate,focusedDate:constrainValue(focusedDate,minValue,maxValue)}}}function getNextPage(focusedDate,startDate,visibleDuration,locale,minValue,maxValue){const adjust=getAdjustedDateFn(visibleDuration,locale,minValue,maxValue);const start=startDate.add(visibleDuration);return adjust({focusedDate:focusedDate.add(visibleDuration),startDate:alignStart(constrainStart(focusedDate,start,visibleDuration,locale,minValue,maxValue),visibleDuration,locale)})}function getPreviousPage(focusedDate,startDate,visibleDuration,locale,minValue,maxValue){const adjust=getAdjustedDateFn(visibleDuration,locale,minValue,maxValue);let start=startDate.subtract(visibleDuration);return adjust({focusedDate:focusedDate.subtract(visibleDuration),startDate:alignStart(constrainStart(focusedDate,start,visibleDuration,locale,minValue,maxValue),visibleDuration,locale)})}function getNextRow(focusedDate,startDate,visibleDuration,locale,minValue,maxValue){const adjust=getAdjustedDateFn(visibleDuration,locale,minValue,maxValue);if(visibleDuration.days){return getNextPage(focusedDate,startDate,visibleDuration,locale,minValue,maxValue)}if(visibleDuration.weeks||visibleDuration.months||visibleDuration.years){return adjust({focusedDate:focusedDate.add({weeks:1}),startDate})}}function getPreviousRow(focusedDate,startDate,visibleDuration,locale,minValue,maxValue){const adjust=getAdjustedDateFn(visibleDuration,locale,minValue,maxValue);if(visibleDuration.days){return getPreviousPage(focusedDate,startDate,visibleDuration,locale,minValue,maxValue)}if(visibleDuration.weeks||visibleDuration.months||visibleDuration.years){return adjust({focusedDate:focusedDate.subtract({weeks:1}),startDate})}}function getSectionStart(focusedDate,startDate,visibleDuration,locale,minValue,maxValue){const adjust=getAdjustedDateFn(visibleDuration,locale,minValue,maxValue);if(visibleDuration.days){return adjust({focusedDate:startDate,startDate})}if(visibleDuration.weeks){return adjust({focusedDate:(0,import_date11.startOfWeek)(focusedDate,locale),startDate})}if(visibleDuration.months||visibleDuration.years){return adjust({focusedDate:(0,import_date11.startOfMonth)(focusedDate),startDate})}}function getSectionEnd(focusedDate,startDate,visibleDuration,locale,minValue,maxValue){const adjust=getAdjustedDateFn(visibleDuration,locale,minValue,maxValue);const endDate=getEndDate(startDate,visibleDuration);if(visibleDuration.days){return adjust({focusedDate:endDate,startDate})}if(visibleDuration.weeks){return adjust({focusedDate:(0,import_date11.endOfWeek)(focusedDate,locale),startDate})}if(visibleDuration.months||visibleDuration.years){return adjust({focusedDate:(0,import_date11.endOfMonth)(focusedDate),startDate})}}function getNextSection(focusedDate,startDate,larger,visibleDuration,locale,minValue,maxValue){const adjust=getAdjustedDateFn(visibleDuration,locale,minValue,maxValue);if(!larger&&!visibleDuration.days){return adjust({focusedDate:focusedDate.add(getUnitDuration(visibleDuration)),startDate})}if(visibleDuration.days){return getNextPage(focusedDate,startDate,visibleDuration,locale,minValue,maxValue)}if(visibleDuration.weeks){return adjust({focusedDate:focusedDate.add({months:1}),startDate})}if(visibleDuration.months||visibleDuration.years){return adjust({focusedDate:focusedDate.add({years:1}),startDate})}}function getPreviousSection(focusedDate,startDate,larger,visibleDuration,locale,minValue,maxValue){const adjust=getAdjustedDateFn(visibleDuration,locale,minValue,maxValue);if(!larger&&!visibleDuration.days){return adjust({focusedDate:focusedDate.subtract(getUnitDuration(visibleDuration)),startDate})}if(visibleDuration.days){return getPreviousPage(focusedDate,startDate,visibleDuration,locale,minValue,maxValue)}if(visibleDuration.weeks){return adjust({focusedDate:focusedDate.subtract({months:1}),startDate})}if(visibleDuration.months||visibleDuration.years){return adjust({focusedDate:focusedDate.subtract({years:1}),startDate})}}var import_date12=require("@internationalized/date");var isValidYear=year=>year!=null&&year.length===4;var isValidMonth=month=>month!=null&&parseFloat(month)<=12;var isValidDay=day=>day!=null&&parseFloat(day)<=31;function parseDateString(date,locale,timeZone){const regex=createRegex(locale,timeZone);let{year,month,day}=extract(regex,date)??{};const hasMatch=year!=null||month!=null||day!=null;if(hasMatch){const curr=new Date;year||(year=curr.getFullYear().toString());month||(month=(curr.getMonth()+1).toString());day||(day=curr.getDate().toString())}if(isValidYear(year)&&isValidMonth(month)&&isValidDay(day)){return new import_date12.CalendarDate(+year,+month,+day)}const time=Date.parse(date);if(!isNaN(time)){const date2=new Date(time);return new import_date12.CalendarDate(date2.getFullYear(),date2.getMonth()+1,date2.getDate())}}function createRegex(locale,timeZone){const formatter=new import_date12.DateFormatter(locale,{day:"numeric",month:"numeric",year:"numeric",timeZone});const parts=formatter.formatToParts(new Date(2e3,11,25));return parts.map(({type,value})=>type==="literal"?`${value}?`:`((?!=<${type}>)\\d+)?`).join("")}function extract(pattern,str){const matches=str.match(pattern);return pattern.toString().match(/<(.+?)>/g)?.map(group=>{const groupMatches=group.match(/<(.+)>/);if(!groupMatches||groupMatches.length<=0){return null}return group.match(/<(.+)>/)?.[1]}).reduce((acc,curr,index)=>{if(!curr)return acc;if(matches&&matches.length>index){acc[curr]=matches[index+1]}else{acc[curr]=null}return acc},{})}var import_date13=require("@internationalized/date");function getDateRangePreset(preset,locale,timeZone){const today4=(0,import_date13.now)(timeZone);switch(preset){case"thisWeek":return[(0,import_date13.startOfWeek)(today4,locale),(0,import_date13.endOfWeek)(today4,locale)];case"thisMonth":return[(0,import_date13.startOfMonth)(today4),today4];case"thisQuarter":return[(0,import_date13.startOfMonth)(today4).add({months:-today4.month%3}),today4];case"thisYear":return[(0,import_date13.startOfYear)(today4),today4];case"last3Days":return[today4.add({days:-2}),today4];case"last7Days":return[today4.add({days:-6}),today4];case"last14Days":return[today4.add({days:-13}),today4];case"last30Days":return[today4.add({days:-29}),today4];case"last90Days":return[today4.add({days:-89}),today4];case"lastMonth":return[(0,import_date13.startOfMonth)(today4.add({months:-1})),(0,import_date13.endOfMonth)(today4.add({months:-1}))];case"lastQuarter":return[(0,import_date13.startOfMonth)(today4.add({months:-today4.month%3-3})),(0,import_date13.endOfMonth)(today4.add({months:-today4.month%3-1}))];case"lastWeek":return[(0,import_date13.startOfWeek)(today4,locale).add({weeks:-1}),(0,import_date13.endOfWeek)(today4,locale).add({weeks:-1})];case"lastYear":return[(0,import_date13.startOfYear)(today4.add({years:-1})),(0,import_date13.endOfYear)(today4.add({years:-1}))];default:throw new Error(`Invalid date range preset: ${preset}`)}}0&&(module.exports={alignCenter,alignDate,alignEnd,alignStart,alignStartDate,constrainStart,constrainValue,formatRange,formatSelectedDate,formatVisibleRange,getAdjustedDateFn,getCustomWeeksInMonth,getDateRangePreset,getDayFormatter,getDaysInWeek,getDecadeRange,getEndDate,getMonthDays,getMonthFormatter,getMonthNames,getNextDay,getNextPage,getNextRow,getNextSection,getPreviousAvailableDate,getPreviousDay,getPreviousPage,getPreviousRow,getPreviousSection,getSectionEnd,getSectionStart,getTodayDate,getUnitDuration,getWeekDays,getWeekdayFormats,getYearsRange,isDateDisabled,isDateEqual,isDateInvalid,isDateOutsideVisibleRange,isDateUnavailable,isNextVisibleRangeInvalid,isPreviousVisibleRangeInvalid,isTodayDate,parseDateString,setCalendar,setDate,setMonth,setYear});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ alignCenter: () => alignCenter,
24
+ alignDate: () => alignDate,
25
+ alignEnd: () => alignEnd,
26
+ alignStart: () => alignStart,
27
+ alignStartDate: () => alignStartDate,
28
+ constrainStart: () => constrainStart,
29
+ constrainValue: () => constrainValue,
30
+ formatRange: () => formatRange,
31
+ formatSelectedDate: () => formatSelectedDate,
32
+ formatVisibleRange: () => formatVisibleRange,
33
+ getAdjustedDateFn: () => getAdjustedDateFn,
34
+ getCustomWeeksInMonth: () => getCustomWeeksInMonth,
35
+ getDateRangePreset: () => getDateRangePreset,
36
+ getDayFormatter: () => getDayFormatter,
37
+ getDaysInWeek: () => getDaysInWeek,
38
+ getDecadeRange: () => getDecadeRange,
39
+ getEndDate: () => getEndDate,
40
+ getMonthDays: () => getMonthDays,
41
+ getMonthFormatter: () => getMonthFormatter,
42
+ getMonthNames: () => getMonthNames,
43
+ getNextDay: () => getNextDay,
44
+ getNextPage: () => getNextPage,
45
+ getNextRow: () => getNextRow,
46
+ getNextSection: () => getNextSection,
47
+ getPreviousAvailableDate: () => getPreviousAvailableDate,
48
+ getPreviousDay: () => getPreviousDay,
49
+ getPreviousPage: () => getPreviousPage,
50
+ getPreviousRow: () => getPreviousRow,
51
+ getPreviousSection: () => getPreviousSection,
52
+ getSectionEnd: () => getSectionEnd,
53
+ getSectionStart: () => getSectionStart,
54
+ getTodayDate: () => getTodayDate,
55
+ getUnitDuration: () => getUnitDuration,
56
+ getWeekDays: () => getWeekDays,
57
+ getWeekdayFormats: () => getWeekdayFormats,
58
+ getYearsRange: () => getYearsRange,
59
+ isDateDisabled: () => isDateDisabled,
60
+ isDateEqual: () => isDateEqual,
61
+ isDateInvalid: () => isDateInvalid,
62
+ isDateOutsideVisibleRange: () => isDateOutsideVisibleRange,
63
+ isDateUnavailable: () => isDateUnavailable,
64
+ isNextVisibleRangeInvalid: () => isNextVisibleRangeInvalid,
65
+ isPreviousVisibleRangeInvalid: () => isPreviousVisibleRangeInvalid,
66
+ isTodayDate: () => isTodayDate,
67
+ parseDateString: () => parseDateString,
68
+ setCalendar: () => setCalendar,
69
+ setDate: () => setDate,
70
+ setMonth: () => setMonth,
71
+ setYear: () => setYear
72
+ });
73
+ module.exports = __toCommonJS(src_exports);
74
+
75
+ // src/constrain.ts
76
+ var import_date = require("@internationalized/date");
77
+ function alignCenter(date, duration, locale, min, max) {
78
+ let halfDuration = {};
79
+ for (let key in duration) {
80
+ halfDuration[key] = Math.floor(duration[key] / 2);
81
+ if (halfDuration[key] > 0 && duration[key] % 2 === 0) {
82
+ halfDuration[key]--;
83
+ }
84
+ }
85
+ let aligned = alignStart(date, duration, locale).subtract(halfDuration);
86
+ return constrainStart(date, aligned, duration, locale, min, max);
87
+ }
88
+ function alignStart(date, duration, locale, min, max) {
89
+ let aligned = date;
90
+ if (duration.years) {
91
+ aligned = (0, import_date.startOfYear)(date);
92
+ } else if (duration.months) {
93
+ aligned = (0, import_date.startOfMonth)(date);
94
+ } else if (duration.weeks) {
95
+ aligned = (0, import_date.startOfWeek)(date, locale);
96
+ }
97
+ return constrainStart(date, aligned, duration, locale, min, max);
98
+ }
99
+ function alignEnd(date, duration, locale, min, max) {
100
+ let d = { ...duration };
101
+ if (d.days) {
102
+ d.days--;
103
+ } else if (d.weeks) {
104
+ d.weeks--;
105
+ } else if (d.months) {
106
+ d.months--;
107
+ } else if (d.years) {
108
+ d.years--;
109
+ }
110
+ let aligned = alignStart(date, duration, locale).subtract(d);
111
+ return constrainStart(date, aligned, duration, locale, min, max);
112
+ }
113
+ function constrainStart(date, aligned, duration, locale, min, max) {
114
+ if (min && date.compare(min) >= 0) {
115
+ aligned = (0, import_date.maxDate)(aligned, alignStart((0, import_date.toCalendarDate)(min), duration, locale));
116
+ }
117
+ if (max && date.compare(max) <= 0) {
118
+ aligned = (0, import_date.minDate)(aligned, alignEnd((0, import_date.toCalendarDate)(max), duration, locale));
119
+ }
120
+ return aligned;
121
+ }
122
+ function constrainValue(date, minValue, maxValue) {
123
+ if (minValue) {
124
+ date = (0, import_date.maxDate)(date, (0, import_date.toCalendarDate)(minValue));
125
+ }
126
+ if (maxValue) {
127
+ date = (0, import_date.minDate)(date, (0, import_date.toCalendarDate)(maxValue));
128
+ }
129
+ return date;
130
+ }
131
+
132
+ // src/align.ts
133
+ function alignDate(date, alignment, duration, locale, min, max) {
134
+ switch (alignment) {
135
+ case "start":
136
+ return alignStart(date, duration, locale, min, max);
137
+ case "end":
138
+ return alignEnd(date, duration, locale, min, max);
139
+ case "center":
140
+ default:
141
+ return alignCenter(date, duration, locale, min, max);
142
+ }
143
+ }
144
+ function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
145
+ if (date.compare(startDate) < 0) {
146
+ return alignEnd(date, duration, locale, min, max);
147
+ }
148
+ if (date.compare(endDate) > 0) {
149
+ return alignStart(date, duration, locale, min, max);
150
+ }
151
+ return startDate;
152
+ }
153
+
154
+ // src/assertion.ts
155
+ var import_date2 = require("@internationalized/date");
156
+ function isTodayDate(date, timeZone) {
157
+ return (0, import_date2.isToday)(date, timeZone);
158
+ }
159
+ function isDateEqual(dateA, dateB) {
160
+ return dateB != null && (0, import_date2.isSameDay)(dateA, dateB);
161
+ }
162
+ function isDateInvalid(date, minValue, maxValue) {
163
+ return minValue != null && date.compare(minValue) < 0 || maxValue != null && date.compare(maxValue) > 0;
164
+ }
165
+ function isDateDisabled(date, startDate, endDate, minValue, maxValue) {
166
+ return isDateOutsideVisibleRange(date, startDate, endDate) || isDateInvalid(date, minValue, maxValue);
167
+ }
168
+ function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
169
+ if (!date) {
170
+ return false;
171
+ }
172
+ if (isUnavailable?.(date, locale)) {
173
+ return true;
174
+ }
175
+ return isDateInvalid(date, minValue, maxValue);
176
+ }
177
+ function isDateOutsideVisibleRange(date, startDate, endDate) {
178
+ return date.compare(startDate) < 0 || date.compare(endDate) > 0;
179
+ }
180
+ function isPreviousVisibleRangeInvalid(startDate, minValue, maxValue) {
181
+ const prevDate = startDate.subtract({ days: 1 });
182
+ return (0, import_date2.isSameDay)(prevDate, startDate) || isDateInvalid(prevDate, minValue, maxValue);
183
+ }
184
+ function isNextVisibleRangeInvalid(endDate, minValue, maxValue) {
185
+ const nextDate = endDate.add({ days: 1 });
186
+ return (0, import_date2.isSameDay)(nextDate, endDate) || isDateInvalid(nextDate, minValue, maxValue);
187
+ }
188
+
189
+ // src/duration.ts
190
+ function getUnitDuration(duration) {
191
+ let d = { ...duration };
192
+ for (let key in d) {
193
+ d[key] = 1;
194
+ }
195
+ return d;
196
+ }
197
+ function getEndDate(startDate, duration) {
198
+ let d = { ...duration };
199
+ if (d.days) {
200
+ d.days--;
201
+ } else {
202
+ d.days = -1;
203
+ }
204
+ return startDate.add(d);
205
+ }
206
+
207
+ // src/format-range.ts
208
+ function formatRange(startDate, endDate, formatter, toString, timeZone) {
209
+ let parts = formatter.formatRangeToParts(startDate.toDate(timeZone), endDate.toDate(timeZone));
210
+ let separatorIndex = -1;
211
+ for (let i = 0; i < parts.length; i++) {
212
+ let part = parts[i];
213
+ if (part.source === "shared" && part.type === "literal") {
214
+ separatorIndex = i;
215
+ } else if (part.source === "endRange") {
216
+ break;
217
+ }
218
+ }
219
+ let start = "";
220
+ let end = "";
221
+ for (let i = 0; i < parts.length; i++) {
222
+ if (i < separatorIndex) {
223
+ start += parts[i].value;
224
+ } else if (i > separatorIndex) {
225
+ end += parts[i].value;
226
+ }
227
+ }
228
+ return toString(start, end);
229
+ }
230
+
231
+ // src/format-selected-date.ts
232
+ var import_date4 = require("@internationalized/date");
233
+
234
+ // src/get-day-formatter.ts
235
+ var import_date3 = require("@internationalized/date");
236
+
237
+ // src/get-era-format.ts
238
+ function getEraFormat(date) {
239
+ return date?.calendar.identifier === "gregory" && date.era === "BC" ? "short" : void 0;
240
+ }
241
+
242
+ // src/get-day-formatter.ts
243
+ function getDayFormatter(locale, timeZone) {
244
+ const date = (0, import_date3.toCalendarDateTime)((0, import_date3.today)(timeZone));
245
+ return new import_date3.DateFormatter(locale, {
246
+ weekday: "long",
247
+ month: "long",
248
+ year: "numeric",
249
+ day: "numeric",
250
+ era: getEraFormat(date),
251
+ timeZone
252
+ });
253
+ }
254
+
255
+ // src/format-selected-date.ts
256
+ function formatSelectedDate(startDate, endDate, locale, timeZone) {
257
+ let start = startDate;
258
+ let end = endDate ?? startDate;
259
+ let formatter = getDayFormatter(locale, timeZone);
260
+ if ((0, import_date4.isSameDay)(start, end)) {
261
+ return formatter.format(start.toDate(timeZone));
262
+ }
263
+ return formatRange(start, end, formatter, (start2, end2) => `${start2} \u2013 ${end2}`, timeZone);
264
+ }
265
+
266
+ // src/format-visible-range.ts
267
+ var import_date6 = require("@internationalized/date");
268
+
269
+ // src/get-month-formatter.ts
270
+ var import_date5 = require("@internationalized/date");
271
+ function getMonthFormatter(locale, timeZone) {
272
+ const date = (0, import_date5.toCalendarDate)((0, import_date5.today)(timeZone));
273
+ return new import_date5.DateFormatter(locale, {
274
+ month: "long",
275
+ year: "numeric",
276
+ era: getEraFormat(date),
277
+ calendar: date?.calendar.identifier,
278
+ timeZone
279
+ });
280
+ }
281
+
282
+ // src/format-visible-range.ts
283
+ function formatVisibleRange(startDate, endDate, locale, timeZone) {
284
+ const start = startDate;
285
+ const end = endDate ?? startDate;
286
+ const dayFormatter = getDayFormatter(locale, timeZone);
287
+ if (!(0, import_date6.isSameDay)(start, (0, import_date6.startOfMonth)(start))) {
288
+ return dayFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
289
+ }
290
+ const monthFormatter = getMonthFormatter(locale, timeZone);
291
+ if ((0, import_date6.isSameDay)(end, (0, import_date6.endOfMonth)(start))) {
292
+ return monthFormatter.format(start.toDate(timeZone));
293
+ }
294
+ if ((0, import_date6.isSameDay)(end, (0, import_date6.endOfMonth)(end))) {
295
+ return monthFormatter.formatRange(start.toDate(timeZone), end.toDate(timeZone));
296
+ }
297
+ return "";
298
+ }
299
+
300
+ // src/get-decade-range.ts
301
+ function getDecadeRange(year) {
302
+ const computedYear = year - year % 10 - 1;
303
+ const years = [];
304
+ for (let i = 0; i < 12; i += 1) {
305
+ const value = computedYear + i;
306
+ years.push(value);
307
+ }
308
+ return years;
309
+ }
310
+
311
+ // src/get-month-days.ts
312
+ var import_date8 = require("@internationalized/date");
313
+
314
+ // src/get-start-of-week.ts
315
+ var import_date7 = require("@internationalized/date");
316
+ function getStartOfWeek(date, locale, firstDayOfWeek = 0) {
317
+ const day = (0, import_date7.getDayOfWeek)(date, locale);
318
+ const diff = (day - firstDayOfWeek + 7) % 7;
319
+ return date.subtract({ days: diff });
320
+ }
321
+
322
+ // src/get-month-days.ts
323
+ function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
324
+ const weekDate = from.add({ weeks: weekIndex });
325
+ const dates = [];
326
+ let date = getStartOfWeek(weekDate, locale, firstDayOfWeek);
327
+ while (dates.length < 7) {
328
+ dates.push(date);
329
+ let nextDate = date.add({ days: 1 });
330
+ if ((0, import_date8.isSameDay)(date, nextDate)) {
331
+ break;
332
+ }
333
+ date = nextDate;
334
+ }
335
+ return dates;
336
+ }
337
+ function getCustomWeeksInMonth(from, locale, firstDayOfWeek) {
338
+ if (firstDayOfWeek == null) {
339
+ return (0, import_date8.getWeeksInMonth)(from, locale);
340
+ }
341
+ const paddingDays = ((0, import_date8.getDayOfWeek)((0, import_date8.startOfMonth)(from), locale) - firstDayOfWeek + 7) % 7;
342
+ return Math.ceil((paddingDays + from.calendar.getDaysInMonth(from)) / 7);
343
+ }
344
+ function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
345
+ const monthWeeks = numOfWeeks ?? getCustomWeeksInMonth(from, locale, firstDayOfWeek);
346
+ const weeks = [...new Array(monthWeeks).keys()];
347
+ return weeks.map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
348
+ }
349
+
350
+ // src/get-month-names.ts
351
+ function getMonthNames(locale, format = "long") {
352
+ const date = new Date(2021, 0, 1);
353
+ const monthNames = [];
354
+ for (let i = 0; i < 12; i++) {
355
+ monthNames.push(date.toLocaleString(locale, { month: format }));
356
+ date.setMonth(date.getMonth() + 1);
357
+ }
358
+ return monthNames;
359
+ }
360
+
361
+ // src/get-weekday-formats.ts
362
+ var import_date9 = require("@internationalized/date");
363
+ function getWeekdayFormats(locale, timeZone) {
364
+ const longFormat = new import_date9.DateFormatter(locale, { weekday: "long", timeZone });
365
+ const shortFormat = new import_date9.DateFormatter(locale, { weekday: "short", timeZone });
366
+ const narrowFormat = new import_date9.DateFormatter(locale, { weekday: "narrow", timeZone });
367
+ return (value) => {
368
+ const date = value instanceof Date ? value : value.toDate(timeZone);
369
+ return {
370
+ value,
371
+ short: shortFormat.format(date),
372
+ long: longFormat.format(date),
373
+ narrow: narrowFormat.format(date)
374
+ };
375
+ };
376
+ }
377
+
378
+ // src/get-week-days.ts
379
+ function getWeekDays(date, startOfWeekProp, timeZone, locale) {
380
+ const firstDayOfWeek = getStartOfWeek(date, locale, startOfWeekProp);
381
+ const weeks = [...new Array(7).keys()];
382
+ const format = getWeekdayFormats(locale, timeZone);
383
+ return weeks.map((index) => format(firstDayOfWeek.add({ days: index })));
384
+ }
385
+
386
+ // src/get-year-range.ts
387
+ function getYearsRange(range) {
388
+ const years = [];
389
+ for (let year = range.from; year <= range.to; year += 1) {
390
+ years.push(year);
391
+ }
392
+ return years;
393
+ }
394
+
395
+ // src/mutation.ts
396
+ var import_date10 = require("@internationalized/date");
397
+ function getTodayDate(timeZone) {
398
+ return (0, import_date10.today)(timeZone ?? (0, import_date10.getLocalTimeZone)());
399
+ }
400
+ function getNextDay(date) {
401
+ return date.add({ days: 1 });
402
+ }
403
+ function getPreviousDay(date) {
404
+ return date.subtract({ days: 1 });
405
+ }
406
+ function setMonth(date, month) {
407
+ return date.set({ month });
408
+ }
409
+ function setYear(date, year) {
410
+ return date.set({ year });
411
+ }
412
+ function setCalendar(date, calendar) {
413
+ return (0, import_date10.toCalendar)((0, import_date10.toCalendarDateTime)(date), calendar);
414
+ }
415
+ function setDate(date, startDate, isDateUnavailable2, locale, minValue, maxValue) {
416
+ let result;
417
+ result = constrainValue(date, minValue, maxValue);
418
+ result = getPreviousAvailableDate(date, startDate, locale, isDateUnavailable2);
419
+ return result;
420
+ }
421
+ function getPreviousAvailableDate(date, minValue, locale, isDateUnavailable2) {
422
+ if (!isDateUnavailable2) {
423
+ return date;
424
+ }
425
+ while (date.compare(minValue) >= 0 && isDateUnavailable2(date, locale)) {
426
+ date = date.subtract({ days: 1 });
427
+ }
428
+ if (date.compare(minValue) >= 0) {
429
+ return date;
430
+ }
431
+ }
432
+
433
+ // src/pagination.ts
434
+ var import_date11 = require("@internationalized/date");
435
+ function getAdjustedDateFn(visibleDuration, locale, minValue, maxValue) {
436
+ return function getDate(options) {
437
+ const { startDate, focusedDate } = options;
438
+ const endDate = getEndDate(startDate, visibleDuration);
439
+ if (isDateInvalid(focusedDate, minValue, maxValue)) {
440
+ return {
441
+ startDate,
442
+ focusedDate: constrainValue(focusedDate, minValue, maxValue),
443
+ endDate
444
+ };
445
+ }
446
+ if (focusedDate.compare(startDate) < 0) {
447
+ return {
448
+ startDate: alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue),
449
+ focusedDate: constrainValue(focusedDate, minValue, maxValue),
450
+ endDate
451
+ };
452
+ }
453
+ if (focusedDate.compare(endDate) > 0) {
454
+ return {
455
+ startDate: alignStart(focusedDate, visibleDuration, locale, minValue, maxValue),
456
+ endDate,
457
+ focusedDate: constrainValue(focusedDate, minValue, maxValue)
458
+ };
459
+ }
460
+ return {
461
+ startDate,
462
+ endDate,
463
+ focusedDate: constrainValue(focusedDate, minValue, maxValue)
464
+ };
465
+ };
466
+ }
467
+ function getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
468
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
469
+ const start = startDate.add(visibleDuration);
470
+ return adjust({
471
+ focusedDate: focusedDate.add(visibleDuration),
472
+ startDate: alignStart(
473
+ constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
474
+ visibleDuration,
475
+ locale
476
+ )
477
+ });
478
+ }
479
+ function getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
480
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
481
+ let start = startDate.subtract(visibleDuration);
482
+ return adjust({
483
+ focusedDate: focusedDate.subtract(visibleDuration),
484
+ startDate: alignStart(
485
+ constrainStart(focusedDate, start, visibleDuration, locale, minValue, maxValue),
486
+ visibleDuration,
487
+ locale
488
+ )
489
+ });
490
+ }
491
+ function getNextRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
492
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
493
+ if (visibleDuration.days) {
494
+ return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
495
+ }
496
+ if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
497
+ return adjust({
498
+ focusedDate: focusedDate.add({ weeks: 1 }),
499
+ startDate
500
+ });
501
+ }
502
+ }
503
+ function getPreviousRow(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
504
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
505
+ if (visibleDuration.days) {
506
+ return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
507
+ }
508
+ if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
509
+ return adjust({
510
+ focusedDate: focusedDate.subtract({ weeks: 1 }),
511
+ startDate
512
+ });
513
+ }
514
+ }
515
+ function getSectionStart(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
516
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
517
+ if (visibleDuration.days) {
518
+ return adjust({
519
+ focusedDate: startDate,
520
+ startDate
521
+ });
522
+ }
523
+ if (visibleDuration.weeks) {
524
+ return adjust({
525
+ focusedDate: (0, import_date11.startOfWeek)(focusedDate, locale),
526
+ startDate
527
+ });
528
+ }
529
+ if (visibleDuration.months || visibleDuration.years) {
530
+ return adjust({
531
+ focusedDate: (0, import_date11.startOfMonth)(focusedDate),
532
+ startDate
533
+ });
534
+ }
535
+ }
536
+ function getSectionEnd(focusedDate, startDate, visibleDuration, locale, minValue, maxValue) {
537
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
538
+ const endDate = getEndDate(startDate, visibleDuration);
539
+ if (visibleDuration.days) {
540
+ return adjust({
541
+ focusedDate: endDate,
542
+ startDate
543
+ });
544
+ }
545
+ if (visibleDuration.weeks) {
546
+ return adjust({
547
+ //@ts-expect-error - endOfWeek is loosely typed
548
+ focusedDate: (0, import_date11.endOfWeek)(focusedDate, locale),
549
+ startDate
550
+ });
551
+ }
552
+ if (visibleDuration.months || visibleDuration.years) {
553
+ return adjust({
554
+ focusedDate: (0, import_date11.endOfMonth)(focusedDate),
555
+ startDate
556
+ });
557
+ }
558
+ }
559
+ function getNextSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
560
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
561
+ if (!larger && !visibleDuration.days) {
562
+ return adjust({
563
+ focusedDate: focusedDate.add(getUnitDuration(visibleDuration)),
564
+ startDate
565
+ });
566
+ }
567
+ if (visibleDuration.days) {
568
+ return getNextPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
569
+ }
570
+ if (visibleDuration.weeks) {
571
+ return adjust({
572
+ focusedDate: focusedDate.add({ months: 1 }),
573
+ startDate
574
+ });
575
+ }
576
+ if (visibleDuration.months || visibleDuration.years) {
577
+ return adjust({
578
+ focusedDate: focusedDate.add({ years: 1 }),
579
+ startDate
580
+ });
581
+ }
582
+ }
583
+ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, locale, minValue, maxValue) {
584
+ const adjust = getAdjustedDateFn(visibleDuration, locale, minValue, maxValue);
585
+ if (!larger && !visibleDuration.days) {
586
+ return adjust({
587
+ focusedDate: focusedDate.subtract(getUnitDuration(visibleDuration)),
588
+ startDate
589
+ });
590
+ }
591
+ if (visibleDuration.days) {
592
+ return getPreviousPage(focusedDate, startDate, visibleDuration, locale, minValue, maxValue);
593
+ }
594
+ if (visibleDuration.weeks) {
595
+ return adjust({
596
+ focusedDate: focusedDate.subtract({ months: 1 }),
597
+ startDate
598
+ });
599
+ }
600
+ if (visibleDuration.months || visibleDuration.years) {
601
+ return adjust({
602
+ focusedDate: focusedDate.subtract({ years: 1 }),
603
+ startDate
604
+ });
605
+ }
606
+ }
607
+
608
+ // src/parse-date.ts
609
+ var import_date12 = require("@internationalized/date");
610
+ var isValidYear = (year) => year != null && year.length === 4;
611
+ var isValidMonth = (month) => month != null && parseFloat(month) <= 12;
612
+ var isValidDay = (day) => day != null && parseFloat(day) <= 31;
613
+ function parseDateString(date, locale, timeZone) {
614
+ const regex = createRegex(locale, timeZone);
615
+ let { year, month, day } = extract(regex, date) ?? {};
616
+ const hasMatch = year != null || month != null || day != null;
617
+ if (hasMatch) {
618
+ const curr = /* @__PURE__ */ new Date();
619
+ year || (year = curr.getFullYear().toString());
620
+ month || (month = (curr.getMonth() + 1).toString());
621
+ day || (day = curr.getDate().toString());
622
+ }
623
+ if (isValidYear(year) && isValidMonth(month) && isValidDay(day)) {
624
+ return new import_date12.CalendarDate(+year, +month, +day);
625
+ }
626
+ const time = Date.parse(date);
627
+ if (!isNaN(time)) {
628
+ const date2 = new Date(time);
629
+ return new import_date12.CalendarDate(date2.getFullYear(), date2.getMonth() + 1, date2.getDate());
630
+ }
631
+ }
632
+ function createRegex(locale, timeZone) {
633
+ const formatter = new import_date12.DateFormatter(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone });
634
+ const parts = formatter.formatToParts(new Date(2e3, 11, 25));
635
+ return parts.map(({ type, value }) => type === "literal" ? `${value}?` : `((?!=<${type}>)\\d+)?`).join("");
636
+ }
637
+ function extract(pattern, str) {
638
+ const matches = str.match(pattern);
639
+ return pattern.toString().match(/<(.+?)>/g)?.map((group) => {
640
+ const groupMatches = group.match(/<(.+)>/);
641
+ if (!groupMatches || groupMatches.length <= 0) {
642
+ return null;
643
+ }
644
+ return group.match(/<(.+)>/)?.[1];
645
+ }).reduce((acc, curr, index) => {
646
+ if (!curr)
647
+ return acc;
648
+ if (matches && matches.length > index) {
649
+ acc[curr] = matches[index + 1];
650
+ } else {
651
+ acc[curr] = null;
652
+ }
653
+ return acc;
654
+ }, {});
655
+ }
656
+
657
+ // src/preset.ts
658
+ var import_date13 = require("@internationalized/date");
659
+ function getDateRangePreset(preset, locale, timeZone) {
660
+ const today4 = (0, import_date13.now)(timeZone);
661
+ switch (preset) {
662
+ case "thisWeek":
663
+ return [(0, import_date13.startOfWeek)(today4, locale), (0, import_date13.endOfWeek)(today4, locale)];
664
+ case "thisMonth":
665
+ return [(0, import_date13.startOfMonth)(today4), today4];
666
+ case "thisQuarter":
667
+ return [(0, import_date13.startOfMonth)(today4).add({ months: -today4.month % 3 }), today4];
668
+ case "thisYear":
669
+ return [(0, import_date13.startOfYear)(today4), today4];
670
+ case "last3Days":
671
+ return [today4.add({ days: -2 }), today4];
672
+ case "last7Days":
673
+ return [today4.add({ days: -6 }), today4];
674
+ case "last14Days":
675
+ return [today4.add({ days: -13 }), today4];
676
+ case "last30Days":
677
+ return [today4.add({ days: -29 }), today4];
678
+ case "last90Days":
679
+ return [today4.add({ days: -89 }), today4];
680
+ case "lastMonth":
681
+ return [(0, import_date13.startOfMonth)(today4.add({ months: -1 })), (0, import_date13.endOfMonth)(today4.add({ months: -1 }))];
682
+ case "lastQuarter":
683
+ return [
684
+ (0, import_date13.startOfMonth)(today4.add({ months: -today4.month % 3 - 3 })),
685
+ (0, import_date13.endOfMonth)(today4.add({ months: -today4.month % 3 - 1 }))
686
+ ];
687
+ case "lastWeek":
688
+ return [(0, import_date13.startOfWeek)(today4, locale).add({ weeks: -1 }), (0, import_date13.endOfWeek)(today4, locale).add({ weeks: -1 })];
689
+ case "lastYear":
690
+ return [(0, import_date13.startOfYear)(today4.add({ years: -1 })), (0, import_date13.endOfYear)(today4.add({ years: -1 }))];
691
+ default:
692
+ throw new Error(`Invalid date range preset: ${preset}`);
693
+ }
694
+ }
695
+ // Annotate the CommonJS export names for ESM import in node:
696
+ 0 && (module.exports = {
697
+ alignCenter,
698
+ alignDate,
699
+ alignEnd,
700
+ alignStart,
701
+ alignStartDate,
702
+ constrainStart,
703
+ constrainValue,
704
+ formatRange,
705
+ formatSelectedDate,
706
+ formatVisibleRange,
707
+ getAdjustedDateFn,
708
+ getCustomWeeksInMonth,
709
+ getDateRangePreset,
710
+ getDayFormatter,
711
+ getDaysInWeek,
712
+ getDecadeRange,
713
+ getEndDate,
714
+ getMonthDays,
715
+ getMonthFormatter,
716
+ getMonthNames,
717
+ getNextDay,
718
+ getNextPage,
719
+ getNextRow,
720
+ getNextSection,
721
+ getPreviousAvailableDate,
722
+ getPreviousDay,
723
+ getPreviousPage,
724
+ getPreviousRow,
725
+ getPreviousSection,
726
+ getSectionEnd,
727
+ getSectionStart,
728
+ getTodayDate,
729
+ getUnitDuration,
730
+ getWeekDays,
731
+ getWeekdayFormats,
732
+ getYearsRange,
733
+ isDateDisabled,
734
+ isDateEqual,
735
+ isDateInvalid,
736
+ isDateOutsideVisibleRange,
737
+ isDateUnavailable,
738
+ isNextVisibleRangeInvalid,
739
+ isPreviousVisibleRangeInvalid,
740
+ isTodayDate,
741
+ parseDateString,
742
+ setCalendar,
743
+ setDate,
744
+ setMonth,
745
+ setYear
746
+ });
2
747
  //# sourceMappingURL=index.js.map