@datepicker-react/hooks
Advanced tools
Comparing version 1.2.2-alpha.0 to 1.2.3-alpha.0
@@ -1,1 +0,927 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react"),MILLISECONDS_IN_MINUTE=6e4,getTimezoneOffsetInMilliseconds=function(e){var t=new Date(e.getTime()),r=t.getTimezoneOffset();t.setSeconds(0,0);var n=t.getTime()%MILLISECONDS_IN_MINUTE;return r*MILLISECONDS_IN_MINUTE+n};function isDate(e){return e instanceof Date}var is_date=isDate,MILLISECONDS_IN_HOUR=36e5,MILLISECONDS_IN_MINUTE$1=6e4,DEFAULT_ADDITIONAL_DIGITS=2,parseTokenDateTimeDelimeter=/[T ]/,parseTokenPlainTime=/:/,parseTokenYY=/^(\d{2})$/,parseTokensYYY=[/^([+-]\d{2})$/,/^([+-]\d{3})$/,/^([+-]\d{4})$/],parseTokenYYYY=/^(\d{4})/,parseTokensYYYYY=[/^([+-]\d{4})/,/^([+-]\d{5})/,/^([+-]\d{6})/],parseTokenMM=/^-(\d{2})$/,parseTokenDDD=/^-?(\d{3})$/,parseTokenMMDD=/^-?(\d{2})-?(\d{2})$/,parseTokenWww=/^-?W(\d{2})$/,parseTokenWwwD=/^-?W(\d{2})-?(\d{1})$/,parseTokenHH=/^(\d{2}([.,]\d*)?)$/,parseTokenHHMM=/^(\d{2}):?(\d{2}([.,]\d*)?)$/,parseTokenHHMMSS=/^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/,parseTokenTimezone=/([Z+-].*)$/,parseTokenTimezoneZ=/^(Z)$/,parseTokenTimezoneHH=/^([+-])(\d{2})$/,parseTokenTimezoneHHMM=/^([+-])(\d{2}):?(\d{2})$/;function parse(e,t){if(is_date(e))return new Date(e.getTime());if("string"!=typeof e)return new Date(e);var r=(t||{}).additionalDigits;r=null==r?DEFAULT_ADDITIONAL_DIGITS:Number(r);var n=splitDateString(e),a=parseYear(n.date,r),o=a.year,s=parseDate(a.restDateString,o);if(s){var i,u=s.getTime(),f=0;if(n.time&&(f=parseTime(n.time)),n.timezone)i=parseTimezone(n.timezone)*MILLISECONDS_IN_MINUTE$1;else{var d=u+f,c=new Date(d);i=getTimezoneOffsetInMilliseconds(c);var _=new Date(d);_.setDate(c.getDate()+1);var D=getTimezoneOffsetInMilliseconds(_)-getTimezoneOffsetInMilliseconds(c);D>0&&(i+=D)}return new Date(u+f+i)}return new Date(e)}function splitDateString(e){var t,r={},n=e.split(parseTokenDateTimeDelimeter);if(parseTokenPlainTime.test(n[0])?(r.date=null,t=n[0]):(r.date=n[0],t=n[1]),t){var a=parseTokenTimezone.exec(t);a?(r.time=t.replace(a[1],""),r.timezone=a[1]):r.time=t}return r}function parseYear(e,t){var r,n=parseTokensYYY[t],a=parseTokensYYYYY[t];if(r=parseTokenYYYY.exec(e)||a.exec(e)){var o=r[1];return{year:parseInt(o,10),restDateString:e.slice(o.length)}}if(r=parseTokenYY.exec(e)||n.exec(e)){var s=r[1];return{year:100*parseInt(s,10),restDateString:e.slice(s.length)}}return{year:null}}function parseDate(e,t){if(null===t)return null;var r,n,a;if(0===e.length)return(n=new Date(0)).setUTCFullYear(t),n;if(r=parseTokenMM.exec(e))return n=new Date(0),a=parseInt(r[1],10)-1,n.setUTCFullYear(t,a),n;if(r=parseTokenDDD.exec(e)){n=new Date(0);var o=parseInt(r[1],10);return n.setUTCFullYear(t,0,o),n}if(r=parseTokenMMDD.exec(e)){n=new Date(0),a=parseInt(r[1],10)-1;var s=parseInt(r[2],10);return n.setUTCFullYear(t,a,s),n}return(r=parseTokenWww.exec(e))?dayOfISOYear(t,parseInt(r[1],10)-1):(r=parseTokenWwwD.exec(e))?dayOfISOYear(t,parseInt(r[1],10)-1,parseInt(r[2],10)-1):null}function parseTime(e){var t,r,n;if(t=parseTokenHH.exec(e))return(r=parseFloat(t[1].replace(",",".")))%24*MILLISECONDS_IN_HOUR;if(t=parseTokenHHMM.exec(e))return r=parseInt(t[1],10),n=parseFloat(t[2].replace(",",".")),r%24*MILLISECONDS_IN_HOUR+n*MILLISECONDS_IN_MINUTE$1;if(t=parseTokenHHMMSS.exec(e)){r=parseInt(t[1],10),n=parseInt(t[2],10);var a=parseFloat(t[3].replace(",","."));return r%24*MILLISECONDS_IN_HOUR+n*MILLISECONDS_IN_MINUTE$1+1e3*a}return null}function parseTimezone(e){var t,r;return(t=parseTokenTimezoneZ.exec(e))?0:(t=parseTokenTimezoneHH.exec(e))?(r=60*parseInt(t[2],10),"+"===t[1]?-r:r):(t=parseTokenTimezoneHHMM.exec(e))?(r=60*parseInt(t[2],10)+parseInt(t[3],10),"+"===t[1]?-r:r):0}function dayOfISOYear(e,t,r){t=t||0,r=r||0;var n=new Date(0);n.setUTCFullYear(e,0,4);var a=7*t+r+1-(n.getUTCDay()||7);return n.setUTCDate(n.getUTCDate()+a),n}var parse_1=parse;function startOfYear(e){var t=parse_1(e),r=new Date(0);return r.setFullYear(t.getFullYear(),0,1),r.setHours(0,0,0,0),r}var start_of_year=startOfYear;function startOfDay(e){var t=parse_1(e);return t.setHours(0,0,0,0),t}var start_of_day=startOfDay,MILLISECONDS_IN_MINUTE$2=6e4,MILLISECONDS_IN_DAY=864e5;function differenceInCalendarDays(e,t){var r=start_of_day(e),n=start_of_day(t),a=r.getTime()-r.getTimezoneOffset()*MILLISECONDS_IN_MINUTE$2,o=n.getTime()-n.getTimezoneOffset()*MILLISECONDS_IN_MINUTE$2;return Math.round((a-o)/MILLISECONDS_IN_DAY)}var difference_in_calendar_days=differenceInCalendarDays;function getDayOfYear(e){var t=parse_1(e);return difference_in_calendar_days(t,start_of_year(t))+1}var get_day_of_year=getDayOfYear;function startOfWeek(e,t){var r=t&&Number(t.weekStartsOn)||0,n=parse_1(e),a=n.getDay(),o=(a<r?7:0)+a-r;return n.setDate(n.getDate()-o),n.setHours(0,0,0,0),n}var start_of_week=startOfWeek;function startOfISOWeek(e){return start_of_week(e,{weekStartsOn:1})}var start_of_iso_week=startOfISOWeek;function getISOYear(e){var t=parse_1(e),r=t.getFullYear(),n=new Date(0);n.setFullYear(r+1,0,4),n.setHours(0,0,0,0);var a=start_of_iso_week(n),o=new Date(0);o.setFullYear(r,0,4),o.setHours(0,0,0,0);var s=start_of_iso_week(o);return t.getTime()>=a.getTime()?r+1:t.getTime()>=s.getTime()?r:r-1}var get_iso_year=getISOYear;function startOfISOYear(e){var t=get_iso_year(e),r=new Date(0);return r.setFullYear(t,0,4),r.setHours(0,0,0,0),start_of_iso_week(r)}var start_of_iso_year=startOfISOYear,MILLISECONDS_IN_WEEK=6048e5;function getISOWeek(e){var t=parse_1(e),r=start_of_iso_week(t).getTime()-start_of_iso_year(t).getTime();return Math.round(r/MILLISECONDS_IN_WEEK)+1}var get_iso_week=getISOWeek;function isValid(e){if(is_date(e))return!isNaN(e);throw new TypeError(toString.call(e)+" is not an instance of Date")}var is_valid=isValid;function buildDistanceInWordsLocale(){var e={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};return{localize:function(t,r,n){var a;return n=n||{},a="string"==typeof e[t]?e[t]:1===r?e[t].one:e[t].other.replace("{{count}}",r),n.addSuffix?n.comparison>0?"in "+a:a+" ago":a}}}var build_distance_in_words_locale=buildDistanceInWordsLocale,commonFormatterKeys=["M","MM","Q","D","DD","DDD","DDDD","d","E","W","WW","YY","YYYY","GG","GGGG","H","HH","h","hh","m","mm","s","ss","S","SS","SSS","Z","ZZ","X","x"];function buildFormattingTokensRegExp(e){var t=[];for(var r in e)e.hasOwnProperty(r)&&t.push(r);var n=commonFormatterKeys.concat(t).sort().reverse();return new RegExp("(\\[[^\\[]*\\])|(\\\\)?("+n.join("|")+"|.)","g")}var build_formatting_tokens_reg_exp=buildFormattingTokensRegExp;function buildFormatLocale(){var e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],t=["January","February","March","April","May","June","July","August","September","October","November","December"],r=["Su","Mo","Tu","We","Th","Fr","Sa"],n=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],a=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],o=["AM","PM"],s=["am","pm"],i=["a.m.","p.m."],u={MMM:function(t){return e[t.getMonth()]},MMMM:function(e){return t[e.getMonth()]},dd:function(e){return r[e.getDay()]},ddd:function(e){return n[e.getDay()]},dddd:function(e){return a[e.getDay()]},A:function(e){return e.getHours()/12>=1?o[1]:o[0]},a:function(e){return e.getHours()/12>=1?s[1]:s[0]},aa:function(e){return e.getHours()/12>=1?i[1]:i[0]}};return["M","D","DDD","d","Q","W"].forEach(function(e){u[e+"o"]=function(t,r){return ordinal(r[e](t))}}),{formatters:u,formattingTokensRegExp:build_formatting_tokens_reg_exp(u)}}function ordinal(e){var t=e%100;if(t>20||t<10)switch(t%10){case 1:return e+"st";case 2:return e+"nd";case 3:return e+"rd"}return e+"th"}var build_format_locale=buildFormatLocale,en={distanceInWords:build_distance_in_words_locale(),format:build_format_locale()};function format(e,t,r){var n=t?String(t):"YYYY-MM-DDTHH:mm:ss.SSSZ",a=(r||{}).locale,o=en.format.formatters,s=en.format.formattingTokensRegExp;a&&a.format&&a.format.formatters&&(o=a.format.formatters,a.format.formattingTokensRegExp&&(s=a.format.formattingTokensRegExp));var i=parse_1(e);return is_valid(i)?buildFormatFn(n,o,s)(i):"Invalid Date"}var formatters={M:function(e){return e.getMonth()+1},MM:function(e){return addLeadingZeros(e.getMonth()+1,2)},Q:function(e){return Math.ceil((e.getMonth()+1)/3)},D:function(e){return e.getDate()},DD:function(e){return addLeadingZeros(e.getDate(),2)},DDD:function(e){return get_day_of_year(e)},DDDD:function(e){return addLeadingZeros(get_day_of_year(e),3)},d:function(e){return e.getDay()},E:function(e){return e.getDay()||7},W:function(e){return get_iso_week(e)},WW:function(e){return addLeadingZeros(get_iso_week(e),2)},YY:function(e){return addLeadingZeros(e.getFullYear(),4).substr(2)},YYYY:function(e){return addLeadingZeros(e.getFullYear(),4)},GG:function(e){return String(get_iso_year(e)).substr(2)},GGGG:function(e){return get_iso_year(e)},H:function(e){return e.getHours()},HH:function(e){return addLeadingZeros(e.getHours(),2)},h:function(e){var t=e.getHours();return 0===t?12:t>12?t%12:t},hh:function(e){return addLeadingZeros(formatters.h(e),2)},m:function(e){return e.getMinutes()},mm:function(e){return addLeadingZeros(e.getMinutes(),2)},s:function(e){return e.getSeconds()},ss:function(e){return addLeadingZeros(e.getSeconds(),2)},S:function(e){return Math.floor(e.getMilliseconds()/100)},SS:function(e){return addLeadingZeros(Math.floor(e.getMilliseconds()/10),2)},SSS:function(e){return addLeadingZeros(e.getMilliseconds(),3)},Z:function(e){return formatTimezone(e.getTimezoneOffset(),":")},ZZ:function(e){return formatTimezone(e.getTimezoneOffset())},X:function(e){return Math.floor(e.getTime()/1e3)},x:function(e){return e.getTime()}};function buildFormatFn(e,t,r){var n,a,o=e.match(r),s=o.length;for(n=0;n<s;n++)a=t[o[n]]||formatters[o[n]],o[n]=a||removeFormattingTokens(o[n]);return function(e){for(var t="",r=0;r<s;r++)o[r]instanceof Function?t+=o[r](e,formatters):t+=o[r];return t}}function removeFormattingTokens(e){return e.match(/\[[\s\S]/)?e.replace(/^\[|]$/g,""):e.replace(/\\/g,"")}function formatTimezone(e,t){t=t||"";var r=e>0?"-":"+",n=Math.abs(e),a=n%60;return r+addLeadingZeros(Math.floor(n/60),2)+t+addLeadingZeros(a,2)}function addLeadingZeros(e,t){for(var r=Math.abs(e).toString();r.length<t;)r="0"+r;return r}var format_1=format;function addDays(e,t){var r=parse_1(e),n=Number(t);return r.setDate(r.getDate()+n),r}var add_days=addDays;function eachDay(e,t,r){var n=parse_1(e),a=void 0!==r?r:1,o=parse_1(t).getTime();if(n.getTime()>o)throw new Error("The first date cannot be after the second date");var s=[],i=n;for(i.setHours(0,0,0,0);i.getTime()<=o;)s.push(parse_1(i)),i.setDate(i.getDate()+a);return s}var each_day=eachDay;function endOfMonth(e){var t=parse_1(e),r=t.getMonth();return t.setFullYear(t.getFullYear(),r+1,0),t.setHours(23,59,59,999),t}var end_of_month=endOfMonth;function endOfWeek(e,t){var r=t&&Number(t.weekStartsOn)||0,n=parse_1(e),a=n.getDay(),o=6+(a<r?-7:0)-(a-r);return n.setDate(n.getDate()+o),n.setHours(23,59,59,999),n}var end_of_week=endOfWeek;function getDay(e){return parse_1(e).getDay()}var get_day=getDay;function startOfMonth(e){var t=parse_1(e);return t.setDate(1),t.setHours(0,0,0,0),t}var start_of_month=startOfMonth;function getWeekDays(e){var t=void 0===e?{}:e,r=t.weekStartsOn,n=void 0===r?1:r,a=t.weekDayFormat,o=void 0===a?function(e){return format_1(e,"dd")}:a,s=new Date;return each_day(add_days(start_of_week(s),n),add_days(end_of_week(s),n)).reduce(function(e,t){return e.push(o(t)),e},[])}function getDays(e){var t=e.year,r=e.month,n=e.weekStartsOn,a=void 0===n?1:n,o=e.dayFormat,s=void 0===o?function(e){return format_1(e,"DD")}:o,i=new Date(t,r),u=start_of_month(i),f=get_day(u),d=end_of_month(i),c=Array.from(Array(f>=a?f-a:a).keys()).fill(0),_=each_day(u,d).map(function(e){return{date:e,day:s(e)}});return c.concat(_)}function useMonth(e){var t=e.year,r=e.month,n=e.weekStartsOn,a=void 0===n?1:n,o=e.dayFormat,s=void 0===o?function(e){return format_1(e,"DD")}:o,i=e.weekDayFormat,u=void 0===i?function(e){return format_1(e,"dd")}:i,f=e.monthLabelFormat,d=void 0===f?function(e){return format_1(e,"MMMM YYYY")}:f;return{days:react.useMemo(function(){return getDays({year:t,month:r,weekStartsOn:a,dayFormat:s})},[t,r,a]),weekDays:react.useMemo(function(){return getWeekDays({weekStartsOn:a,weekDayFormat:u})},[a]),monthLabel:d(new Date(t,r))}}function isBefore(e,t){var r=parse_1(e),n=parse_1(t);return r.getTime()<n.getTime()}var is_before=isBefore;function isAfter(e,t){var r=parse_1(e),n=parse_1(t);return r.getTime()>n.getTime()}var is_after=isAfter;function isWithinRange(e,t,r){var n=parse_1(e).getTime(),a=parse_1(t).getTime(),o=parse_1(r).getTime();if(a>o)throw new Error("The start of the range cannot be after the end of the range");return n>=a&&n<=o}var is_within_range=isWithinRange;function isSameDay(e,t){var r=start_of_day(e),n=start_of_day(t);return r.getTime()===n.getTime()}var is_same_day=isSameDay;function getYear(e){return parse_1(e).getFullYear()}var get_year=getYear;function getMonth(e){return parse_1(e).getMonth()}var get_month=getMonth;function startOfToday(){return start_of_day(new Date)}var start_of_today=startOfToday;function getDaysInMonth(e){var t=parse_1(e),r=t.getFullYear(),n=t.getMonth(),a=new Date(0);return a.setFullYear(r,n+1,0),a.setHours(0,0,0,0),a.getDate()}var get_days_in_month=getDaysInMonth;function addMonths(e,t){var r=parse_1(e),n=Number(t),a=r.getMonth()+n,o=new Date(0);o.setFullYear(r.getFullYear(),a,1),o.setHours(0,0,0,0);var s=get_days_in_month(o);return r.setMonth(a,Math.min(s,r.getDate())),r}var add_months=addMonths;function isDateSelected(e,t,r){return!(!t||!r)&&is_within_range(e,t,r)}function isStartOrEndDate(e,t,r){return!!(t&&is_same_day(e,t)||r&&is_same_day(e,r))}function isDateBlocked(e,t,r,n){var a=t?new Date(t.getFullYear(),t.getMonth(),t.getDate(),0,0,0):t,o=r?new Date(r.getFullYear(),r.getMonth(),r.getDate(),0,0,0):r;return!!(a&&is_before(e,a)||o&&is_after(e,o)||n&&n(e))}function getDateMonthAndYear(e){var t=start_of_month(e);return{year:get_year(t),month:get_month(t),date:t}}function getCurrentYearMonthAndDate(){return getDateMonthAndYear(start_of_today())}function getInitialMonths(e,t){var r=t?getDateMonthAndYear(t):getCurrentYearMonthAndDate(),n=r.date,a=[r];return e>1&&(a=Array.from(Array(e-1).keys()).reduce(function(e){return n=add_months(e[e.length-1].date,1),e.concat([getDateMonthAndYear(n)])},a)),a}function getNextActiveMonth(e,t,r){var n=e[r>0?e.length-1:0].date;return Array.from(Array(t).keys()).reduce(function(e){return n=add_months(n,r),r>0?e.concat([getDateMonthAndYear(n)]):[getDateMonthAndYear(n)].concat(e)},[])}function getInputValue(e,t,r){return e&&"string"==typeof t?format_1(e,t):e&&"function"==typeof t?t(e):r}var START_DATE="startDate",END_DATE="endDate";function useDatepicker(e){var t=e.startDate,r=e.endDate,n=e.focusedInput,a=e.minBookingDate,o=e.maxBookingDate,s=e.onDateChange,i=e.numberOfMonths,u=void 0===i?2:i,f=e.firstDayOfWeek,d=void 0===f?1:f,c=react.useState(function(){return getInitialMonths(u,t)}),_=c[0],D=c[1],g=react.useCallback(function(e){return isDateSelected(e,t,r)},[t,r]),l=react.useCallback(function(e){return isStartOrEndDate(e,t,r)},[t,r]),m=react.useCallback(function(e){return isDateBlocked(e,a,o)},[a,o]);return{firstDayOfWeek:d,activeMonths:_,isDateSelected:g,isStartOrEndDate:l,isDateBlocked:m,numberOfMonths:u,onResetDates:function(){s({startDate:null,endDate:null,focusedInput:START_DATE})},onDaySelect:function(e){n===END_DATE&&t&&is_before(e,t)||n===START_DATE&&r&&is_after(e,r)?s({endDate:null,startDate:e,focusedInput:END_DATE}):n===START_DATE?s({endDate:r,startDate:e,focusedInput:END_DATE}):n===END_DATE&&t&&!is_before(e,t)&&s({startDate:t,endDate:e,focusedInput:null})},goToPreviousMonths:function(){D(getNextActiveMonth(_,u,-1))},goToNextMonths:function(){D(getNextActiveMonth(_,u,1))}}}exports.END_DATE=END_DATE,exports.START_DATE=START_DATE,exports.getCurrentYearMonthAndDate=getCurrentYearMonthAndDate,exports.getDateMonthAndYear=getDateMonthAndYear,exports.getDays=getDays,exports.getInitialMonths=getInitialMonths,exports.getInputValue=getInputValue,exports.getWeekDays=getWeekDays,exports.isDateBlocked=isDateBlocked,exports.isDateSelected=isDateSelected,exports.isStartOrEndDate=isStartOrEndDate,exports.useDatepicker=useDatepicker,exports.useMonth=useMonth; | ||
'use strict' | ||
Object.defineProperty(exports, '__esModule', {value: !0}) | ||
var react = require('react'), | ||
MILLISECONDS_IN_MINUTE = 6e4, | ||
getTimezoneOffsetInMilliseconds = function(e) { | ||
var t = new Date(e.getTime()), | ||
a = t.getTimezoneOffset() | ||
t.setSeconds(0, 0) | ||
var r = t.getTime() % MILLISECONDS_IN_MINUTE | ||
return a * MILLISECONDS_IN_MINUTE + r | ||
} | ||
function isDate(e) { | ||
return e instanceof Date | ||
} | ||
var is_date = isDate, | ||
MILLISECONDS_IN_HOUR = 36e5, | ||
MILLISECONDS_IN_MINUTE$1 = 6e4, | ||
DEFAULT_ADDITIONAL_DIGITS = 2, | ||
parseTokenDateTimeDelimeter = /[T ]/, | ||
parseTokenPlainTime = /:/, | ||
parseTokenYY = /^(\d{2})$/, | ||
parseTokensYYY = [/^([+-]\d{2})$/, /^([+-]\d{3})$/, /^([+-]\d{4})$/], | ||
parseTokenYYYY = /^(\d{4})/, | ||
parseTokensYYYYY = [/^([+-]\d{4})/, /^([+-]\d{5})/, /^([+-]\d{6})/], | ||
parseTokenMM = /^-(\d{2})$/, | ||
parseTokenDDD = /^-?(\d{3})$/, | ||
parseTokenMMDD = /^-?(\d{2})-?(\d{2})$/, | ||
parseTokenWww = /^-?W(\d{2})$/, | ||
parseTokenWwwD = /^-?W(\d{2})-?(\d{1})$/, | ||
parseTokenHH = /^(\d{2}([.,]\d*)?)$/, | ||
parseTokenHHMM = /^(\d{2}):?(\d{2}([.,]\d*)?)$/, | ||
parseTokenHHMMSS = /^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/, | ||
parseTokenTimezone = /([Z+-].*)$/, | ||
parseTokenTimezoneZ = /^(Z)$/, | ||
parseTokenTimezoneHH = /^([+-])(\d{2})$/, | ||
parseTokenTimezoneHHMM = /^([+-])(\d{2}):?(\d{2})$/ | ||
function parse(e, t) { | ||
if (is_date(e)) return new Date(e.getTime()) | ||
if ('string' != typeof e) return new Date(e) | ||
var a = (t || {}).additionalDigits | ||
a = null == a ? DEFAULT_ADDITIONAL_DIGITS : Number(a) | ||
var r = splitDateString(e), | ||
n = parseYear(r.date, a), | ||
o = n.year, | ||
s = parseDate(n.restDateString, o) | ||
if (s) { | ||
var i, | ||
u = s.getTime(), | ||
d = 0 | ||
if ((r.time && (d = parseTime(r.time)), r.timezone)) | ||
i = parseTimezone(r.timezone) * MILLISECONDS_IN_MINUTE$1 | ||
else { | ||
var c = u + d, | ||
f = new Date(c) | ||
i = getTimezoneOffsetInMilliseconds(f) | ||
var D = new Date(c) | ||
D.setDate(f.getDate() + 1) | ||
var _ = getTimezoneOffsetInMilliseconds(D) - getTimezoneOffsetInMilliseconds(f) | ||
_ > 0 && (i += _) | ||
} | ||
return new Date(u + d + i) | ||
} | ||
return new Date(e) | ||
} | ||
function splitDateString(e) { | ||
var t, | ||
a = {}, | ||
r = e.split(parseTokenDateTimeDelimeter) | ||
if ( | ||
(parseTokenPlainTime.test(r[0]) ? ((a.date = null), (t = r[0])) : ((a.date = r[0]), (t = r[1])), | ||
t) | ||
) { | ||
var n = parseTokenTimezone.exec(t) | ||
n ? ((a.time = t.replace(n[1], '')), (a.timezone = n[1])) : (a.time = t) | ||
} | ||
return a | ||
} | ||
function parseYear(e, t) { | ||
var a, | ||
r = parseTokensYYY[t], | ||
n = parseTokensYYYYY[t] | ||
if ((a = parseTokenYYYY.exec(e) || n.exec(e))) { | ||
var o = a[1] | ||
return {year: parseInt(o, 10), restDateString: e.slice(o.length)} | ||
} | ||
if ((a = parseTokenYY.exec(e) || r.exec(e))) { | ||
var s = a[1] | ||
return {year: 100 * parseInt(s, 10), restDateString: e.slice(s.length)} | ||
} | ||
return {year: null} | ||
} | ||
function parseDate(e, t) { | ||
if (null === t) return null | ||
var a, r, n | ||
if (0 === e.length) return (r = new Date(0)).setUTCFullYear(t), r | ||
if ((a = parseTokenMM.exec(e))) | ||
return (r = new Date(0)), (n = parseInt(a[1], 10) - 1), r.setUTCFullYear(t, n), r | ||
if ((a = parseTokenDDD.exec(e))) { | ||
r = new Date(0) | ||
var o = parseInt(a[1], 10) | ||
return r.setUTCFullYear(t, 0, o), r | ||
} | ||
if ((a = parseTokenMMDD.exec(e))) { | ||
;(r = new Date(0)), (n = parseInt(a[1], 10) - 1) | ||
var s = parseInt(a[2], 10) | ||
return r.setUTCFullYear(t, n, s), r | ||
} | ||
return (a = parseTokenWww.exec(e)) | ||
? dayOfISOYear(t, parseInt(a[1], 10) - 1) | ||
: (a = parseTokenWwwD.exec(e)) | ||
? dayOfISOYear(t, parseInt(a[1], 10) - 1, parseInt(a[2], 10) - 1) | ||
: null | ||
} | ||
function parseTime(e) { | ||
var t, a, r | ||
if ((t = parseTokenHH.exec(e))) | ||
return ((a = parseFloat(t[1].replace(',', '.'))) % 24) * MILLISECONDS_IN_HOUR | ||
if ((t = parseTokenHHMM.exec(e))) | ||
return ( | ||
(a = parseInt(t[1], 10)), | ||
(r = parseFloat(t[2].replace(',', '.'))), | ||
(a % 24) * MILLISECONDS_IN_HOUR + r * MILLISECONDS_IN_MINUTE$1 | ||
) | ||
if ((t = parseTokenHHMMSS.exec(e))) { | ||
;(a = parseInt(t[1], 10)), (r = parseInt(t[2], 10)) | ||
var n = parseFloat(t[3].replace(',', '.')) | ||
return (a % 24) * MILLISECONDS_IN_HOUR + r * MILLISECONDS_IN_MINUTE$1 + 1e3 * n | ||
} | ||
return null | ||
} | ||
function parseTimezone(e) { | ||
var t, a | ||
return (t = parseTokenTimezoneZ.exec(e)) | ||
? 0 | ||
: (t = parseTokenTimezoneHH.exec(e)) | ||
? ((a = 60 * parseInt(t[2], 10)), '+' === t[1] ? -a : a) | ||
: (t = parseTokenTimezoneHHMM.exec(e)) | ||
? ((a = 60 * parseInt(t[2], 10) + parseInt(t[3], 10)), '+' === t[1] ? -a : a) | ||
: 0 | ||
} | ||
function dayOfISOYear(e, t, a) { | ||
;(t = t || 0), (a = a || 0) | ||
var r = new Date(0) | ||
r.setUTCFullYear(e, 0, 4) | ||
var n = 7 * t + a + 1 - (r.getUTCDay() || 7) | ||
return r.setUTCDate(r.getUTCDate() + n), r | ||
} | ||
var parse_1 = parse | ||
function startOfYear(e) { | ||
var t = parse_1(e), | ||
a = new Date(0) | ||
return a.setFullYear(t.getFullYear(), 0, 1), a.setHours(0, 0, 0, 0), a | ||
} | ||
var start_of_year = startOfYear | ||
function startOfDay(e) { | ||
var t = parse_1(e) | ||
return t.setHours(0, 0, 0, 0), t | ||
} | ||
var start_of_day = startOfDay, | ||
MILLISECONDS_IN_MINUTE$2 = 6e4, | ||
MILLISECONDS_IN_DAY = 864e5 | ||
function differenceInCalendarDays(e, t) { | ||
var a = start_of_day(e), | ||
r = start_of_day(t), | ||
n = a.getTime() - a.getTimezoneOffset() * MILLISECONDS_IN_MINUTE$2, | ||
o = r.getTime() - r.getTimezoneOffset() * MILLISECONDS_IN_MINUTE$2 | ||
return Math.round((n - o) / MILLISECONDS_IN_DAY) | ||
} | ||
var difference_in_calendar_days = differenceInCalendarDays | ||
function getDayOfYear(e) { | ||
var t = parse_1(e) | ||
return difference_in_calendar_days(t, start_of_year(t)) + 1 | ||
} | ||
var get_day_of_year = getDayOfYear | ||
function startOfWeek(e, t) { | ||
var a = (t && Number(t.weekStartsOn)) || 0, | ||
r = parse_1(e), | ||
n = r.getDay(), | ||
o = (n < a ? 7 : 0) + n - a | ||
return r.setDate(r.getDate() - o), r.setHours(0, 0, 0, 0), r | ||
} | ||
var start_of_week = startOfWeek | ||
function startOfISOWeek(e) { | ||
return start_of_week(e, {weekStartsOn: 1}) | ||
} | ||
var start_of_iso_week = startOfISOWeek | ||
function getISOYear(e) { | ||
var t = parse_1(e), | ||
a = t.getFullYear(), | ||
r = new Date(0) | ||
r.setFullYear(a + 1, 0, 4), r.setHours(0, 0, 0, 0) | ||
var n = start_of_iso_week(r), | ||
o = new Date(0) | ||
o.setFullYear(a, 0, 4), o.setHours(0, 0, 0, 0) | ||
var s = start_of_iso_week(o) | ||
return t.getTime() >= n.getTime() ? a + 1 : t.getTime() >= s.getTime() ? a : a - 1 | ||
} | ||
var get_iso_year = getISOYear | ||
function startOfISOYear(e) { | ||
var t = get_iso_year(e), | ||
a = new Date(0) | ||
return a.setFullYear(t, 0, 4), a.setHours(0, 0, 0, 0), start_of_iso_week(a) | ||
} | ||
var start_of_iso_year = startOfISOYear, | ||
MILLISECONDS_IN_WEEK = 6048e5 | ||
function getISOWeek(e) { | ||
var t = parse_1(e), | ||
a = start_of_iso_week(t).getTime() - start_of_iso_year(t).getTime() | ||
return Math.round(a / MILLISECONDS_IN_WEEK) + 1 | ||
} | ||
var get_iso_week = getISOWeek | ||
function isValid(e) { | ||
if (is_date(e)) return !isNaN(e) | ||
throw new TypeError(toString.call(e) + ' is not an instance of Date') | ||
} | ||
var is_valid = isValid | ||
function buildDistanceInWordsLocale() { | ||
var e = { | ||
lessThanXSeconds: {one: 'less than a second', other: 'less than {{count}} seconds'}, | ||
xSeconds: {one: '1 second', other: '{{count}} seconds'}, | ||
halfAMinute: 'half a minute', | ||
lessThanXMinutes: {one: 'less than a minute', other: 'less than {{count}} minutes'}, | ||
xMinutes: {one: '1 minute', other: '{{count}} minutes'}, | ||
aboutXHours: {one: 'about 1 hour', other: 'about {{count}} hours'}, | ||
xHours: {one: '1 hour', other: '{{count}} hours'}, | ||
xDays: {one: '1 day', other: '{{count}} days'}, | ||
aboutXMonths: {one: 'about 1 month', other: 'about {{count}} months'}, | ||
xMonths: {one: '1 month', other: '{{count}} months'}, | ||
aboutXYears: {one: 'about 1 year', other: 'about {{count}} years'}, | ||
xYears: {one: '1 year', other: '{{count}} years'}, | ||
overXYears: {one: 'over 1 year', other: 'over {{count}} years'}, | ||
almostXYears: {one: 'almost 1 year', other: 'almost {{count}} years'}, | ||
} | ||
return { | ||
localize: function(t, a, r) { | ||
var n | ||
return ( | ||
(r = r || {}), | ||
(n = | ||
'string' == typeof e[t] ? e[t] : 1 === a ? e[t].one : e[t].other.replace('{{count}}', a)), | ||
r.addSuffix ? (r.comparison > 0 ? 'in ' + n : n + ' ago') : n | ||
) | ||
}, | ||
} | ||
} | ||
var build_distance_in_words_locale = buildDistanceInWordsLocale, | ||
commonFormatterKeys = [ | ||
'M', | ||
'MM', | ||
'Q', | ||
'D', | ||
'DD', | ||
'DDD', | ||
'DDDD', | ||
'd', | ||
'E', | ||
'W', | ||
'WW', | ||
'YY', | ||
'YYYY', | ||
'GG', | ||
'GGGG', | ||
'H', | ||
'HH', | ||
'h', | ||
'hh', | ||
'm', | ||
'mm', | ||
's', | ||
'ss', | ||
'S', | ||
'SS', | ||
'SSS', | ||
'Z', | ||
'ZZ', | ||
'X', | ||
'x', | ||
] | ||
function buildFormattingTokensRegExp(e) { | ||
var t = [] | ||
for (var a in e) e.hasOwnProperty(a) && t.push(a) | ||
var r = commonFormatterKeys | ||
.concat(t) | ||
.sort() | ||
.reverse() | ||
return new RegExp('(\\[[^\\[]*\\])|(\\\\)?(' + r.join('|') + '|.)', 'g') | ||
} | ||
var build_formatting_tokens_reg_exp = buildFormattingTokensRegExp | ||
function buildFormatLocale() { | ||
var e = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], | ||
t = [ | ||
'January', | ||
'February', | ||
'March', | ||
'April', | ||
'May', | ||
'June', | ||
'July', | ||
'August', | ||
'September', | ||
'October', | ||
'November', | ||
'December', | ||
], | ||
a = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], | ||
r = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], | ||
n = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], | ||
o = ['AM', 'PM'], | ||
s = ['am', 'pm'], | ||
i = ['a.m.', 'p.m.'], | ||
u = { | ||
MMM: function(t) { | ||
return e[t.getMonth()] | ||
}, | ||
MMMM: function(e) { | ||
return t[e.getMonth()] | ||
}, | ||
dd: function(e) { | ||
return a[e.getDay()] | ||
}, | ||
ddd: function(e) { | ||
return r[e.getDay()] | ||
}, | ||
dddd: function(e) { | ||
return n[e.getDay()] | ||
}, | ||
A: function(e) { | ||
return e.getHours() / 12 >= 1 ? o[1] : o[0] | ||
}, | ||
a: function(e) { | ||
return e.getHours() / 12 >= 1 ? s[1] : s[0] | ||
}, | ||
aa: function(e) { | ||
return e.getHours() / 12 >= 1 ? i[1] : i[0] | ||
}, | ||
} | ||
return ( | ||
['M', 'D', 'DDD', 'd', 'Q', 'W'].forEach(function(e) { | ||
u[e + 'o'] = function(t, a) { | ||
return ordinal(a[e](t)) | ||
} | ||
}), | ||
{formatters: u, formattingTokensRegExp: build_formatting_tokens_reg_exp(u)} | ||
) | ||
} | ||
function ordinal(e) { | ||
var t = e % 100 | ||
if (t > 20 || t < 10) | ||
switch (t % 10) { | ||
case 1: | ||
return e + 'st' | ||
case 2: | ||
return e + 'nd' | ||
case 3: | ||
return e + 'rd' | ||
} | ||
return e + 'th' | ||
} | ||
var build_format_locale = buildFormatLocale, | ||
en = {distanceInWords: build_distance_in_words_locale(), format: build_format_locale()} | ||
function format(e, t, a) { | ||
var r = t ? String(t) : 'YYYY-MM-DDTHH:mm:ss.SSSZ', | ||
n = (a || {}).locale, | ||
o = en.format.formatters, | ||
s = en.format.formattingTokensRegExp | ||
n && | ||
n.format && | ||
n.format.formatters && | ||
((o = n.format.formatters), | ||
n.format.formattingTokensRegExp && (s = n.format.formattingTokensRegExp)) | ||
var i = parse_1(e) | ||
return is_valid(i) ? buildFormatFn(r, o, s)(i) : 'Invalid Date' | ||
} | ||
var formatters = { | ||
M: function(e) { | ||
return e.getMonth() + 1 | ||
}, | ||
MM: function(e) { | ||
return addLeadingZeros(e.getMonth() + 1, 2) | ||
}, | ||
Q: function(e) { | ||
return Math.ceil((e.getMonth() + 1) / 3) | ||
}, | ||
D: function(e) { | ||
return e.getDate() | ||
}, | ||
DD: function(e) { | ||
return addLeadingZeros(e.getDate(), 2) | ||
}, | ||
DDD: function(e) { | ||
return get_day_of_year(e) | ||
}, | ||
DDDD: function(e) { | ||
return addLeadingZeros(get_day_of_year(e), 3) | ||
}, | ||
d: function(e) { | ||
return e.getDay() | ||
}, | ||
E: function(e) { | ||
return e.getDay() || 7 | ||
}, | ||
W: function(e) { | ||
return get_iso_week(e) | ||
}, | ||
WW: function(e) { | ||
return addLeadingZeros(get_iso_week(e), 2) | ||
}, | ||
YY: function(e) { | ||
return addLeadingZeros(e.getFullYear(), 4).substr(2) | ||
}, | ||
YYYY: function(e) { | ||
return addLeadingZeros(e.getFullYear(), 4) | ||
}, | ||
GG: function(e) { | ||
return String(get_iso_year(e)).substr(2) | ||
}, | ||
GGGG: function(e) { | ||
return get_iso_year(e) | ||
}, | ||
H: function(e) { | ||
return e.getHours() | ||
}, | ||
HH: function(e) { | ||
return addLeadingZeros(e.getHours(), 2) | ||
}, | ||
h: function(e) { | ||
var t = e.getHours() | ||
return 0 === t ? 12 : t > 12 ? t % 12 : t | ||
}, | ||
hh: function(e) { | ||
return addLeadingZeros(formatters.h(e), 2) | ||
}, | ||
m: function(e) { | ||
return e.getMinutes() | ||
}, | ||
mm: function(e) { | ||
return addLeadingZeros(e.getMinutes(), 2) | ||
}, | ||
s: function(e) { | ||
return e.getSeconds() | ||
}, | ||
ss: function(e) { | ||
return addLeadingZeros(e.getSeconds(), 2) | ||
}, | ||
S: function(e) { | ||
return Math.floor(e.getMilliseconds() / 100) | ||
}, | ||
SS: function(e) { | ||
return addLeadingZeros(Math.floor(e.getMilliseconds() / 10), 2) | ||
}, | ||
SSS: function(e) { | ||
return addLeadingZeros(e.getMilliseconds(), 3) | ||
}, | ||
Z: function(e) { | ||
return formatTimezone(e.getTimezoneOffset(), ':') | ||
}, | ||
ZZ: function(e) { | ||
return formatTimezone(e.getTimezoneOffset()) | ||
}, | ||
X: function(e) { | ||
return Math.floor(e.getTime() / 1e3) | ||
}, | ||
x: function(e) { | ||
return e.getTime() | ||
}, | ||
} | ||
function buildFormatFn(e, t, a) { | ||
var r, | ||
n, | ||
o = e.match(a), | ||
s = o.length | ||
for (r = 0; r < s; r++) | ||
(n = t[o[r]] || formatters[o[r]]), (o[r] = n || removeFormattingTokens(o[r])) | ||
return function(e) { | ||
for (var t = '', a = 0; a < s; a++) | ||
o[a] instanceof Function ? (t += o[a](e, formatters)) : (t += o[a]) | ||
return t | ||
} | ||
} | ||
function removeFormattingTokens(e) { | ||
return e.match(/\[[\s\S]/) ? e.replace(/^\[|]$/g, '') : e.replace(/\\/g, '') | ||
} | ||
function formatTimezone(e, t) { | ||
t = t || '' | ||
var a = e > 0 ? '-' : '+', | ||
r = Math.abs(e), | ||
n = r % 60 | ||
return a + addLeadingZeros(Math.floor(r / 60), 2) + t + addLeadingZeros(n, 2) | ||
} | ||
function addLeadingZeros(e, t) { | ||
for (var a = Math.abs(e).toString(); a.length < t; ) a = '0' + a | ||
return a | ||
} | ||
var format_1 = format | ||
function addDays(e, t) { | ||
var a = parse_1(e), | ||
r = Number(t) | ||
return a.setDate(a.getDate() + r), a | ||
} | ||
var add_days = addDays | ||
function eachDay(e, t, a) { | ||
var r = parse_1(e), | ||
n = void 0 !== a ? a : 1, | ||
o = parse_1(t).getTime() | ||
if (r.getTime() > o) throw new Error('The first date cannot be after the second date') | ||
var s = [], | ||
i = r | ||
for (i.setHours(0, 0, 0, 0); i.getTime() <= o; ) s.push(parse_1(i)), i.setDate(i.getDate() + n) | ||
return s | ||
} | ||
var each_day = eachDay | ||
function endOfMonth(e) { | ||
var t = parse_1(e), | ||
a = t.getMonth() | ||
return t.setFullYear(t.getFullYear(), a + 1, 0), t.setHours(23, 59, 59, 999), t | ||
} | ||
var end_of_month = endOfMonth | ||
function endOfWeek(e, t) { | ||
var a = (t && Number(t.weekStartsOn)) || 0, | ||
r = parse_1(e), | ||
n = r.getDay(), | ||
o = 6 + (n < a ? -7 : 0) - (n - a) | ||
return r.setDate(r.getDate() + o), r.setHours(23, 59, 59, 999), r | ||
} | ||
var end_of_week = endOfWeek | ||
function getDay(e) { | ||
return parse_1(e).getDay() | ||
} | ||
var get_day = getDay | ||
function startOfMonth(e) { | ||
var t = parse_1(e) | ||
return t.setDate(1), t.setHours(0, 0, 0, 0), t | ||
} | ||
var start_of_month = startOfMonth | ||
function getWeekDays(e) { | ||
var t = void 0 === e ? {} : e, | ||
a = t.weekStartsOn, | ||
r = void 0 === a ? 1 : a, | ||
n = t.weekDayFormat, | ||
o = | ||
void 0 === n | ||
? function(e) { | ||
return format_1(e, 'dd') | ||
} | ||
: n, | ||
s = new Date() | ||
return each_day(add_days(start_of_week(s), r), add_days(end_of_week(s), r)).reduce(function( | ||
e, | ||
t, | ||
) { | ||
return e.push(o(t)), e | ||
}, | ||
[]) | ||
} | ||
function getDays(e) { | ||
var t = e.year, | ||
a = e.month, | ||
r = e.weekStartsOn, | ||
n = void 0 === r ? 1 : r, | ||
o = e.dayFormat, | ||
s = | ||
void 0 === o | ||
? function(e) { | ||
return format_1(e, 'DD') | ||
} | ||
: o, | ||
i = new Date(t, a), | ||
u = start_of_month(i), | ||
d = get_day(u), | ||
c = end_of_month(i), | ||
f = Array.from(Array(d >= n ? d - n : n).keys()).fill(0), | ||
D = each_day(u, c).map(function(e) { | ||
return {date: e, day: s(e)} | ||
}) | ||
return f.concat(D) | ||
} | ||
function useMonth(e) { | ||
var t = e.year, | ||
a = e.month, | ||
r = e.weekStartsOn, | ||
n = void 0 === r ? 1 : r, | ||
o = e.dayFormat, | ||
s = | ||
void 0 === o | ||
? function(e) { | ||
return format_1(e, 'DD') | ||
} | ||
: o, | ||
i = e.weekDayFormat, | ||
u = | ||
void 0 === i | ||
? function(e) { | ||
return format_1(e, 'dd') | ||
} | ||
: i, | ||
d = e.monthLabelFormat, | ||
c = | ||
void 0 === d | ||
? function(e) { | ||
return format_1(e, 'MMMM YYYY') | ||
} | ||
: d | ||
return { | ||
days: react.useMemo( | ||
function() { | ||
return getDays({year: t, month: a, weekStartsOn: n, dayFormat: s}) | ||
}, | ||
[t, a, n, s], | ||
), | ||
weekDays: react.useMemo( | ||
function() { | ||
return getWeekDays({weekStartsOn: n, weekDayFormat: u}) | ||
}, | ||
[n, u], | ||
), | ||
monthLabel: c(new Date(t, a)), | ||
} | ||
} | ||
function isBefore(e, t) { | ||
var a = parse_1(e), | ||
r = parse_1(t) | ||
return a.getTime() < r.getTime() | ||
} | ||
var is_before = isBefore | ||
function isAfter(e, t) { | ||
var a = parse_1(e), | ||
r = parse_1(t) | ||
return a.getTime() > r.getTime() | ||
} | ||
var is_after = isAfter | ||
function isWithinRange(e, t, a) { | ||
var r = parse_1(e).getTime(), | ||
n = parse_1(t).getTime(), | ||
o = parse_1(a).getTime() | ||
if (n > o) throw new Error('The start of the range cannot be after the end of the range') | ||
return r >= n && r <= o | ||
} | ||
var is_within_range = isWithinRange | ||
function isSameDay(e, t) { | ||
var a = start_of_day(e), | ||
r = start_of_day(t) | ||
return a.getTime() === r.getTime() | ||
} | ||
var is_same_day = isSameDay | ||
function getYear(e) { | ||
return parse_1(e).getFullYear() | ||
} | ||
var get_year = getYear | ||
function getMonth(e) { | ||
return parse_1(e).getMonth() | ||
} | ||
var get_month = getMonth | ||
function startOfToday() { | ||
return start_of_day(new Date()) | ||
} | ||
var start_of_today = startOfToday | ||
function getDaysInMonth(e) { | ||
var t = parse_1(e), | ||
a = t.getFullYear(), | ||
r = t.getMonth(), | ||
n = new Date(0) | ||
return n.setFullYear(a, r + 1, 0), n.setHours(0, 0, 0, 0), n.getDate() | ||
} | ||
var get_days_in_month = getDaysInMonth | ||
function addMonths(e, t) { | ||
var a = parse_1(e), | ||
r = Number(t), | ||
n = a.getMonth() + r, | ||
o = new Date(0) | ||
o.setFullYear(a.getFullYear(), n, 1), o.setHours(0, 0, 0, 0) | ||
var s = get_days_in_month(o) | ||
return a.setMonth(n, Math.min(s, a.getDate())), a | ||
} | ||
var add_months = addMonths | ||
function isDateSelected(e, t, a) { | ||
return !(!t || !a) && is_within_range(e, t, a) | ||
} | ||
function isFirstOrLastSelectedDate(e, t, a) { | ||
return !!((t && is_same_day(e, t)) || (a && is_same_day(e, a))) | ||
} | ||
function isDateBlocked(e) { | ||
var t = e.date, | ||
a = e.minBookingDate, | ||
r = e.maxBookingDate, | ||
n = e.isDayBlockedFn, | ||
o = e.startDate, | ||
s = e.endDate, | ||
i = e.minBookingDays, | ||
u = void 0 === i ? 1 : i, | ||
d = a ? new Date(a.getFullYear(), a.getMonth(), a.getDate(), 0, 0, 0) : a, | ||
c = r ? new Date(r.getFullYear(), r.getMonth(), r.getDate(), 0, 0, 0) : r | ||
return !!( | ||
(d && is_before(t, d)) || | ||
(c && is_after(t, c)) || | ||
(o && !s && u > 1 && is_within_range(t, o, add_days(o, u - 2))) || | ||
(n && n(t)) | ||
) | ||
} | ||
function getDateMonthAndYear(e) { | ||
var t = start_of_month(e) | ||
return {year: get_year(t), month: get_month(t), date: t} | ||
} | ||
function getCurrentYearMonthAndDate() { | ||
return getDateMonthAndYear(start_of_today()) | ||
} | ||
function getInitialMonths(e, t) { | ||
var a = t ? getDateMonthAndYear(t) : getCurrentYearMonthAndDate(), | ||
r = a.date, | ||
n = [a] | ||
return ( | ||
e > 1 && | ||
(n = Array.from(Array(e - 1).keys()).reduce(function(e) { | ||
return (r = add_months(e[e.length - 1].date, 1)), e.concat([getDateMonthAndYear(r)]) | ||
}, n)), | ||
n | ||
) | ||
} | ||
function getNextActiveMonth(e, t, a) { | ||
var r = e[a > 0 ? e.length - 1 : 0].date | ||
return Array.from(Array(t).keys()).reduce(function(e) { | ||
return ( | ||
(r = add_months(r, a)), | ||
a > 0 ? e.concat([getDateMonthAndYear(r)]) : [getDateMonthAndYear(r)].concat(e) | ||
) | ||
}, []) | ||
} | ||
function getInputValue(e, t, a) { | ||
return e && 'string' == typeof t ? format_1(e, t) : e && 'function' == typeof t ? t(e) : a | ||
} | ||
function canSelectRange(e) { | ||
var t = e.startDate, | ||
a = e.endDate, | ||
r = e.isDateBlocked, | ||
n = e.minBookingDays, | ||
o = e.exactMinBookingDays, | ||
s = e.minBookingDate, | ||
i = e.maxBookingDate | ||
if (t && 1 === n && !a && !r(t)) return !0 | ||
if ( | ||
(t && n > 1 && !a && !o) || | ||
(t && n > 0 && o && s && i && !is_before(t, s) && !is_after(add_days(t, n - 1), i)) || | ||
(t && n > 0 && o && !s && !i) | ||
) | ||
return each_day(t, add_days(t, n - 1)).reduce(function(e, t) { | ||
return e ? !r(t) : e | ||
}, !0) | ||
if (t && a && !o) { | ||
var u = add_days(t, n - 1) | ||
return ( | ||
!is_before(a, u) && | ||
each_day(t, a).reduce(function(e, t) { | ||
return e ? !r(t) : e | ||
}, !0) | ||
) | ||
} | ||
return !1 | ||
} | ||
function isDateHovered(e) { | ||
var t = e.date, | ||
a = e.startDate, | ||
r = e.endDate, | ||
n = e.isDateBlocked, | ||
o = e.hoveredDate, | ||
s = e.minBookingDays, | ||
i = e.exactMinBookingDays | ||
return o && s > 1 && i && is_within_range(t, o, add_days(o, s - 1)) | ||
? each_day(o, add_days(o, s - 1)).reduce(function(e, t) { | ||
return e ? !n(t) : e | ||
}, !0) | ||
: a && !r && o && is_within_range(t, a, add_days(a, s - 1)) && is_same_day(a, o) && s > 1 | ||
? each_day(a, add_days(a, s - 1)).reduce(function(e, t) { | ||
return e ? !n(t) : e | ||
}, !0) | ||
: !(!a || r || !o || is_before(o, a) || !is_within_range(t, a, o)) && | ||
each_day(a, o).reduce(function(e, t) { | ||
return e ? !n(t) : e | ||
}, !0) | ||
} | ||
var START_DATE = 'startDate', | ||
END_DATE = 'endDate' | ||
function useDatepicker(e) { | ||
var t = e.startDate, | ||
a = e.endDate, | ||
r = e.focusedInput, | ||
n = e.minBookingDate, | ||
o = e.maxBookingDate, | ||
s = e.onDateChange, | ||
i = e.exactMinBookingDays, | ||
u = void 0 !== i && i, | ||
d = e.minBookingDays, | ||
c = void 0 === d ? 1 : d, | ||
f = e.numberOfMonths, | ||
D = void 0 === f ? 2 : f, | ||
_ = e.firstDayOfWeek, | ||
g = void 0 === _ ? 1 : _, | ||
l = e.isDayBlocked, | ||
m = | ||
void 0 === l | ||
? function() { | ||
return !1 | ||
} | ||
: l, | ||
y = react.useState(function() { | ||
return getInitialMonths(D, t) | ||
}), | ||
T = y[0], | ||
h = y[1], | ||
M = react.useState(null), | ||
p = M[0], | ||
v = M[1], | ||
k = react.useCallback( | ||
function(e) { | ||
return isDateSelected(e, t, a) | ||
}, | ||
[t, a], | ||
), | ||
S = react.useCallback( | ||
function(e) { | ||
return isFirstOrLastSelectedDate(e, t, a) | ||
}, | ||
[t, a], | ||
), | ||
I = react.useCallback( | ||
function(e) { | ||
return isDateBlocked({ | ||
date: e, | ||
minBookingDate: n, | ||
maxBookingDate: o, | ||
startDate: t, | ||
endDate: a, | ||
minBookingDays: c, | ||
isDayBlockedFn: m, | ||
}) | ||
}, | ||
[n, o, t, a, c, m], | ||
), | ||
Y = react.useCallback( | ||
function(e) { | ||
return isDateHovered({ | ||
date: e, | ||
hoveredDate: p, | ||
startDate: t, | ||
endDate: a, | ||
minBookingDays: c, | ||
exactMinBookingDays: u, | ||
isDateBlocked: m, | ||
}) | ||
}, | ||
[p, t, a, c, u, m], | ||
) | ||
return { | ||
firstDayOfWeek: g, | ||
activeMonths: T, | ||
isDateSelected: k, | ||
isDateHovered: Y, | ||
isFirstOrLastSelectedDate: S, | ||
isDateBlocked: I, | ||
numberOfMonths: D, | ||
onResetDates: function() { | ||
s({startDate: null, endDate: null, focusedInput: START_DATE}) | ||
}, | ||
onDayHover: function(e) { | ||
;(u && | ||
(c <= 1 || | ||
(n && o && (!is_within_range(e, n, o) || !is_within_range(add_days(e, c - 1), n, o))))) || | ||
(!u && | ||
(!t || | ||
a || | ||
(n && o && !is_within_range(e, n, o)) || | ||
(!is_same_day(e, t) && c > 1 && t && is_within_range(e, t, add_days(t, c - 2))))) | ||
? v(null) | ||
: v(e) | ||
}, | ||
onDaySelect: function(e) { | ||
;(r === END_DATE || r === START_DATE) && | ||
c > 0 && | ||
u && | ||
canSelectRange({ | ||
minBookingDays: c, | ||
exactMinBookingDays: u, | ||
minBookingDate: n, | ||
maxBookingDate: o, | ||
isDateBlocked: m, | ||
startDate: e, | ||
endDate: null, | ||
}) | ||
? s({startDate: e, endDate: add_days(e, c - 1), focusedInput: null}) | ||
: ((r === END_DATE && t && is_before(e, t)) || (r === START_DATE && a && is_after(e, a))) && | ||
!u && | ||
canSelectRange({minBookingDays: c, isDateBlocked: m, startDate: e, endDate: null}) | ||
? s({endDate: null, startDate: e, focusedInput: END_DATE}) | ||
: r === START_DATE && | ||
!u && | ||
canSelectRange({minBookingDays: c, isDateBlocked: m, endDate: a, startDate: e}) | ||
? s({endDate: a, startDate: e, focusedInput: END_DATE}) | ||
: r === START_DATE && | ||
!u && | ||
canSelectRange({minBookingDays: c, isDateBlocked: m, endDate: null, startDate: e}) | ||
? s({endDate: null, startDate: e, focusedInput: END_DATE}) | ||
: r === END_DATE && | ||
t && | ||
!is_before(e, t) && | ||
!u && | ||
canSelectRange({minBookingDays: c, isDateBlocked: m, startDate: t, endDate: e}) && | ||
s({startDate: t, endDate: e, focusedInput: null}) | ||
}, | ||
goToPreviousMonths: function() { | ||
h(getNextActiveMonth(T, D, -1)) | ||
}, | ||
goToNextMonths: function() { | ||
h(getNextActiveMonth(T, D, 1)) | ||
}, | ||
} | ||
} | ||
;(exports.END_DATE = END_DATE), | ||
(exports.START_DATE = START_DATE), | ||
(exports.getCurrentYearMonthAndDate = getCurrentYearMonthAndDate), | ||
(exports.getDateMonthAndYear = getDateMonthAndYear), | ||
(exports.getDays = getDays), | ||
(exports.getInitialMonths = getInitialMonths), | ||
(exports.getInputValue = getInputValue), | ||
(exports.getWeekDays = getWeekDays), | ||
(exports.isDateBlocked = isDateBlocked), | ||
(exports.isDateSelected = isDateSelected), | ||
(exports.isFirstOrLastSelectedDate = isFirstOrLastSelectedDate), | ||
(exports.useDatepicker = useDatepicker), | ||
(exports.useMonth = useMonth) |
import { useMonth, UseMonthProps, UseMonthResult, GetDaysProps, GetWeekDaysProps, getWeekDays, getDays, CalendarDay } from './useMonth'; | ||
import { isDateSelected, isStartOrEndDate, isDateBlocked, getCurrentYearMonthAndDate, getDateMonthAndYear, getInitialMonths, MonthType, useDatepicker, UseDatepickerProps, START_DATE, END_DATE, getInputValue, FormatFunction, FocusedInput, FirstDayOfWeek, OnDateChange } from './useDatepicker'; | ||
export { useMonth, UseMonthProps, UseMonthResult, GetDaysProps, GetWeekDaysProps, getWeekDays, getDays, CalendarDay, isDateSelected, isStartOrEndDate, isDateBlocked, getCurrentYearMonthAndDate, getDateMonthAndYear, getInitialMonths, MonthType, useDatepicker, UseDatepickerProps, START_DATE, END_DATE, getInputValue, FormatFunction, FocusedInput, FirstDayOfWeek, OnDateChange, }; | ||
import { isDateSelected, isFirstOrLastSelectedDate, isDateBlocked, getCurrentYearMonthAndDate, getDateMonthAndYear, getInitialMonths, MonthType, useDatepicker, UseDatepickerProps, START_DATE, END_DATE, getInputValue, FormatFunction, FocusedInput, FirstDayOfWeek, OnDateChange } from './useDatepicker'; | ||
export { useMonth, UseMonthProps, UseMonthResult, GetDaysProps, GetWeekDaysProps, getWeekDays, getDays, CalendarDay, isDateSelected, isFirstOrLastSelectedDate, isDateBlocked, getCurrentYearMonthAndDate, getDateMonthAndYear, getInitialMonths, MonthType, useDatepicker, UseDatepickerProps, START_DATE, END_DATE, getInputValue, FormatFunction, FocusedInput, FirstDayOfWeek, OnDateChange, }; |
@@ -1,1 +0,878 @@ | ||
import{useMemo as e,useState as t,useCallback as r}from"react";var n=function(e){var t=new Date(e.getTime()),r=t.getTimezoneOffset();return t.setSeconds(0,0),6e4*r+t.getTime()%6e4};var a=function(e){return e instanceof Date},u=36e5,o=6e4,i=2,s=/[T ]/,c=/:/,f=/^(\d{2})$/,l=[/^([+-]\d{2})$/,/^([+-]\d{3})$/,/^([+-]\d{4})$/],g=/^(\d{4})/,d=[/^([+-]\d{4})/,/^([+-]\d{5})/,/^([+-]\d{6})/],v=/^-(\d{2})$/,D=/^-?(\d{3})$/,m=/^-?(\d{2})-?(\d{2})$/,h=/^-?W(\d{2})$/,y=/^-?W(\d{2})-?(\d{1})$/,M=/^(\d{2}([.,]\d*)?)$/,T=/^(\d{2}):?(\d{2}([.,]\d*)?)$/,p=/^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/,S=/([Z+-].*)$/,Y=/^(Z)$/,w=/^([+-])(\d{2})$/,F=/^([+-])(\d{2}):?(\d{2})$/;function x(e,t,r){t=t||0,r=r||0;var n=new Date(0);n.setUTCFullYear(e,0,4);var a=7*t+r+1-(n.getUTCDay()||7);return n.setUTCDate(n.getUTCDate()+a),n}var b=function(e,t){if(a(e))return new Date(e.getTime());if("string"!=typeof e)return new Date(e);var r=(t||{}).additionalDigits;r=null==r?i:Number(r);var b=function(e){var t,r={},n=e.split(s);if(c.test(n[0])?(r.date=null,t=n[0]):(r.date=n[0],t=n[1]),t){var a=S.exec(t);a?(r.time=t.replace(a[1],""),r.timezone=a[1]):r.time=t}return r}(e),H=function(e,t){var r,n=l[t],a=d[t];if(r=g.exec(e)||a.exec(e)){var u=r[1];return{year:parseInt(u,10),restDateString:e.slice(u.length)}}if(r=f.exec(e)||n.exec(e)){var o=r[1];return{year:100*parseInt(o,10),restDateString:e.slice(o.length)}}return{year:null}}(b.date,r),k=H.year,I=function(e,t){if(null===t)return null;var r,n,a,u;if(0===e.length)return(n=new Date(0)).setUTCFullYear(t),n;if(r=v.exec(e))return n=new Date(0),a=parseInt(r[1],10)-1,n.setUTCFullYear(t,a),n;if(r=D.exec(e)){n=new Date(0);var o=parseInt(r[1],10);return n.setUTCFullYear(t,0,o),n}if(r=m.exec(e)){n=new Date(0),a=parseInt(r[1],10)-1;var i=parseInt(r[2],10);return n.setUTCFullYear(t,a,i),n}if(r=h.exec(e))return u=parseInt(r[1],10)-1,x(t,u);if(r=y.exec(e)){u=parseInt(r[1],10)-1;var s=parseInt(r[2],10)-1;return x(t,u,s)}return null}(H.restDateString,k);if(I){var O,$=I.getTime(),W=0;if(b.time&&(W=function(e){var t,r,n;if(t=M.exec(e))return(r=parseFloat(t[1].replace(",",".")))%24*u;if(t=T.exec(e))return r=parseInt(t[1],10),n=parseFloat(t[2].replace(",",".")),r%24*u+n*o;if(t=p.exec(e)){r=parseInt(t[1],10),n=parseInt(t[2],10);var a=parseFloat(t[3].replace(",","."));return r%24*u+n*o+1e3*a}return null}(b.time)),b.timezone)z=b.timezone,O=((C=Y.exec(z))?0:(C=w.exec(z))?(X=60*parseInt(C[2],10),"+"===C[1]?-X:X):(C=F.exec(z))?(X=60*parseInt(C[2],10)+parseInt(C[3],10),"+"===C[1]?-X:X):0)*o;else{var A=$+W,E=new Date(A);O=n(E);var G=new Date(A);G.setDate(E.getDate()+1);var N=n(G)-n(E);N>0&&(O+=N)}return new Date($+W+O)}var z,C,X;return new Date(e)};var H=function(e){var t=b(e),r=new Date(0);return r.setFullYear(t.getFullYear(),0,1),r.setHours(0,0,0,0),r};var k=function(e){var t=b(e);return t.setHours(0,0,0,0),t},I=6e4,O=864e5;var $=function(e,t){var r=k(e),n=k(t),a=r.getTime()-r.getTimezoneOffset()*I,u=n.getTime()-n.getTimezoneOffset()*I;return Math.round((a-u)/O)};var W=function(e){var t=b(e);return $(t,H(t))+1};var A=function(e,t){var r=t&&Number(t.weekStartsOn)||0,n=b(e),a=n.getDay(),u=(a<r?7:0)+a-r;return n.setDate(n.getDate()-u),n.setHours(0,0,0,0),n};var E=function(e){return A(e,{weekStartsOn:1})};var G=function(e){var t=b(e),r=t.getFullYear(),n=new Date(0);n.setFullYear(r+1,0,4),n.setHours(0,0,0,0);var a=E(n),u=new Date(0);u.setFullYear(r,0,4),u.setHours(0,0,0,0);var o=E(u);return t.getTime()>=a.getTime()?r+1:t.getTime()>=o.getTime()?r:r-1};var N=function(e){var t=G(e),r=new Date(0);return r.setFullYear(t,0,4),r.setHours(0,0,0,0),E(r)},z=6048e5;var C=function(e){var t=b(e),r=E(t).getTime()-N(t).getTime();return Math.round(r/z)+1};var X=function(e){if(a(e))return!isNaN(e);throw new TypeError(toString.call(e)+" is not an instance of Date")};var Z=["M","MM","Q","D","DD","DDD","DDDD","d","E","W","WW","YY","YYYY","GG","GGGG","H","HH","h","hh","m","mm","s","ss","S","SS","SSS","Z","ZZ","X","x"];var U=function(e){var t=[];for(var r in e)e.hasOwnProperty(r)&&t.push(r);var n=Z.concat(t).sort().reverse();return new RegExp("(\\[[^\\[]*\\])|(\\\\)?("+n.join("|")+"|.)","g")};var J=function(){var e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],t=["January","February","March","April","May","June","July","August","September","October","November","December"],r=["Su","Mo","Tu","We","Th","Fr","Sa"],n=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],a=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],u=["AM","PM"],o=["am","pm"],i=["a.m.","p.m."],s={MMM:function(t){return e[t.getMonth()]},MMMM:function(e){return t[e.getMonth()]},dd:function(e){return r[e.getDay()]},ddd:function(e){return n[e.getDay()]},dddd:function(e){return a[e.getDay()]},A:function(e){return e.getHours()/12>=1?u[1]:u[0]},a:function(e){return e.getHours()/12>=1?o[1]:o[0]},aa:function(e){return e.getHours()/12>=1?i[1]:i[0]}};return["M","D","DDD","d","Q","W"].forEach(function(e){s[e+"o"]=function(t,r){return function(e){var t=e%100;if(t>20||t<10)switch(t%10){case 1:return e+"st";case 2:return e+"nd";case 3:return e+"rd"}return e+"th"}(r[e](t))}}),{formatters:s,formattingTokensRegExp:U(s)}},R={distanceInWords:function(){var e={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};return{localize:function(t,r,n){var a;return n=n||{},a="string"==typeof e[t]?e[t]:1===r?e[t].one:e[t].other.replace("{{count}}",r),n.addSuffix?n.comparison>0?"in "+a:a+" ago":a}}}(),format:J()};var B={M:function(e){return e.getMonth()+1},MM:function(e){return Q(e.getMonth()+1,2)},Q:function(e){return Math.ceil((e.getMonth()+1)/3)},D:function(e){return e.getDate()},DD:function(e){return Q(e.getDate(),2)},DDD:function(e){return W(e)},DDDD:function(e){return Q(W(e),3)},d:function(e){return e.getDay()},E:function(e){return e.getDay()||7},W:function(e){return C(e)},WW:function(e){return Q(C(e),2)},YY:function(e){return Q(e.getFullYear(),4).substr(2)},YYYY:function(e){return Q(e.getFullYear(),4)},GG:function(e){return String(G(e)).substr(2)},GGGG:function(e){return G(e)},H:function(e){return e.getHours()},HH:function(e){return Q(e.getHours(),2)},h:function(e){var t=e.getHours();return 0===t?12:t>12?t%12:t},hh:function(e){return Q(B.h(e),2)},m:function(e){return e.getMinutes()},mm:function(e){return Q(e.getMinutes(),2)},s:function(e){return e.getSeconds()},ss:function(e){return Q(e.getSeconds(),2)},S:function(e){return Math.floor(e.getMilliseconds()/100)},SS:function(e){return Q(Math.floor(e.getMilliseconds()/10),2)},SSS:function(e){return Q(e.getMilliseconds(),3)},Z:function(e){return P(e.getTimezoneOffset(),":")},ZZ:function(e){return P(e.getTimezoneOffset())},X:function(e){return Math.floor(e.getTime()/1e3)},x:function(e){return e.getTime()}};function P(e,t){t=t||"";var r=e>0?"-":"+",n=Math.abs(e),a=n%60;return r+Q(Math.floor(n/60),2)+t+Q(a,2)}function Q(e,t){for(var r=Math.abs(e).toString();r.length<t;)r="0"+r;return r}var L=function(e,t,r){var n=t?String(t):"YYYY-MM-DDTHH:mm:ss.SSSZ",a=(r||{}).locale,u=R.format.formatters,o=R.format.formattingTokensRegExp;a&&a.format&&a.format.formatters&&(u=a.format.formatters,a.format.formattingTokensRegExp&&(o=a.format.formattingTokensRegExp));var i=b(e);return X(i)?function(e,t,r){var n,a,u,o=e.match(r),i=o.length;for(n=0;n<i;n++)a=t[o[n]]||B[o[n]],o[n]=a||((u=o[n]).match(/\[[\s\S]/)?u.replace(/^\[|]$/g,""):u.replace(/\\/g,""));return function(e){for(var t="",r=0;r<i;r++)o[r]instanceof Function?t+=o[r](e,B):t+=o[r];return t}}(n,u,o)(i):"Invalid Date"};var j=function(e,t){var r=b(e),n=Number(t);return r.setDate(r.getDate()+n),r};var q=function(e,t,r){var n=b(e),a=void 0!==r?r:1,u=b(t).getTime();if(n.getTime()>u)throw new Error("The first date cannot be after the second date");var o=[],i=n;for(i.setHours(0,0,0,0);i.getTime()<=u;)o.push(b(i)),i.setDate(i.getDate()+a);return o};var K=function(e){var t=b(e),r=t.getMonth();return t.setFullYear(t.getFullYear(),r+1,0),t.setHours(23,59,59,999),t};var V=function(e,t){var r=t&&Number(t.weekStartsOn)||0,n=b(e),a=n.getDay(),u=6+(a<r?-7:0)-(a-r);return n.setDate(n.getDate()+u),n.setHours(23,59,59,999),n};var _=function(e){return b(e).getDay()};var ee=function(e){var t=b(e);return t.setDate(1),t.setHours(0,0,0,0),t};function te(e){var t=void 0===e?{}:e,r=t.weekStartsOn,n=void 0===r?1:r,a=t.weekDayFormat,u=void 0===a?function(e){return L(e,"dd")}:a,o=new Date;return q(j(A(o),n),j(V(o),n)).reduce(function(e,t){return e.push(u(t)),e},[])}function re(e){var t=e.year,r=e.month,n=e.weekStartsOn,a=void 0===n?1:n,u=e.dayFormat,o=void 0===u?function(e){return L(e,"DD")}:u,i=new Date(t,r),s=ee(i),c=_(s),f=K(i),l=Array.from(Array(c>=a?c-a:a).keys()).fill(0),g=q(s,f).map(function(e){return{date:e,day:o(e)}});return l.concat(g)}function ne(t){var r=t.year,n=t.month,a=t.weekStartsOn,u=void 0===a?1:a,o=t.dayFormat,i=void 0===o?function(e){return L(e,"DD")}:o,s=t.weekDayFormat,c=void 0===s?function(e){return L(e,"dd")}:s,f=t.monthLabelFormat,l=void 0===f?function(e){return L(e,"MMMM YYYY")}:f;return{days:e(function(){return re({year:r,month:n,weekStartsOn:u,dayFormat:i})},[r,n,u]),weekDays:e(function(){return te({weekStartsOn:u,weekDayFormat:c})},[u]),monthLabel:l(new Date(r,n))}}var ae=function(e,t){var r=b(e),n=b(t);return r.getTime()<n.getTime()};var ue=function(e,t){var r=b(e),n=b(t);return r.getTime()>n.getTime()};var oe=function(e,t,r){var n=b(e).getTime(),a=b(t).getTime(),u=b(r).getTime();if(a>u)throw new Error("The start of the range cannot be after the end of the range");return n>=a&&n<=u};var ie=function(e,t){var r=k(e),n=k(t);return r.getTime()===n.getTime()};var se=function(e){return b(e).getFullYear()};var ce=function(e){return b(e).getMonth()};var fe=function(){return k(new Date)};var le=function(e){var t=b(e),r=t.getFullYear(),n=t.getMonth(),a=new Date(0);return a.setFullYear(r,n+1,0),a.setHours(0,0,0,0),a.getDate()};var ge=function(e,t){var r=b(e),n=Number(t),a=r.getMonth()+n,u=new Date(0);u.setFullYear(r.getFullYear(),a,1),u.setHours(0,0,0,0);var o=le(u);return r.setMonth(a,Math.min(o,r.getDate())),r};function de(e,t,r){return!(!t||!r)&&oe(e,t,r)}function ve(e,t,r){return!!(t&&ie(e,t)||r&&ie(e,r))}function De(e,t,r,n){var a=t?new Date(t.getFullYear(),t.getMonth(),t.getDate(),0,0,0):t,u=r?new Date(r.getFullYear(),r.getMonth(),r.getDate(),0,0,0):r;return!!(a&&ae(e,a)||u&&ue(e,u)||n&&n(e))}function me(e){var t=ee(e);return{year:se(t),month:ce(t),date:t}}function he(){return me(fe())}function ye(e,t){var r=t?me(t):he(),n=r.date,a=[r];return e>1&&(a=Array.from(Array(e-1).keys()).reduce(function(e){return n=ge(e[e.length-1].date,1),e.concat([me(n)])},a)),a}function Me(e,t,r){var n=e[r>0?e.length-1:0].date;return Array.from(Array(t).keys()).reduce(function(e){return n=ge(n,r),r>0?e.concat([me(n)]):[me(n)].concat(e)},[])}function Te(e,t,r){return e&&"string"==typeof t?L(e,t):e&&"function"==typeof t?t(e):r}var pe="startDate",Se="endDate";function Ye(e){var n=e.startDate,a=e.endDate,u=e.focusedInput,o=e.minBookingDate,i=e.maxBookingDate,s=e.onDateChange,c=e.numberOfMonths,f=void 0===c?2:c,l=e.firstDayOfWeek,g=void 0===l?1:l,d=t(function(){return ye(f,n)}),v=d[0],D=d[1],m=r(function(e){return de(e,n,a)},[n,a]),h=r(function(e){return ve(e,n,a)},[n,a]),y=r(function(e){return De(e,o,i)},[o,i]);return{firstDayOfWeek:g,activeMonths:v,isDateSelected:m,isStartOrEndDate:h,isDateBlocked:y,numberOfMonths:f,onResetDates:function(){s({startDate:null,endDate:null,focusedInput:pe})},onDaySelect:function(e){u===Se&&n&&ae(e,n)||u===pe&&a&&ue(e,a)?s({endDate:null,startDate:e,focusedInput:Se}):u===pe?s({endDate:a,startDate:e,focusedInput:Se}):u===Se&&n&&!ae(e,n)&&s({startDate:n,endDate:e,focusedInput:null})},goToPreviousMonths:function(){D(Me(v,f,-1))},goToNextMonths:function(){D(Me(v,f,1))}}}export{Se as END_DATE,pe as START_DATE,he as getCurrentYearMonthAndDate,me as getDateMonthAndYear,re as getDays,ye as getInitialMonths,Te as getInputValue,te as getWeekDays,De as isDateBlocked,de as isDateSelected,ve as isStartOrEndDate,Ye as useDatepicker,ne as useMonth}; | ||
import {useMemo as e, useState as t, useCallback as n} from 'react' | ||
var r = function(e) { | ||
var t = new Date(e.getTime()), | ||
n = t.getTimezoneOffset() | ||
return t.setSeconds(0, 0), 6e4 * n + (t.getTime() % 6e4) | ||
} | ||
var a = function(e) { | ||
return e instanceof Date | ||
}, | ||
o = 36e5, | ||
u = 6e4, | ||
i = 2, | ||
s = /[T ]/, | ||
c = /:/, | ||
f = /^(\d{2})$/, | ||
D = [/^([+-]\d{2})$/, /^([+-]\d{3})$/, /^([+-]\d{4})$/], | ||
d = /^(\d{4})/, | ||
l = [/^([+-]\d{4})/, /^([+-]\d{5})/, /^([+-]\d{6})/], | ||
g = /^-(\d{2})$/, | ||
m = /^-?(\d{3})$/, | ||
v = /^-?(\d{2})-?(\d{2})$/, | ||
h = /^-?W(\d{2})$/, | ||
y = /^-?W(\d{2})-?(\d{1})$/, | ||
M = /^(\d{2}([.,]\d*)?)$/, | ||
k = /^(\d{2}):?(\d{2}([.,]\d*)?)$/, | ||
T = /^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/, | ||
p = /([Z+-].*)$/, | ||
S = /^(Z)$/, | ||
Y = /^([+-])(\d{2})$/, | ||
w = /^([+-])(\d{2}):?(\d{2})$/ | ||
function x(e, t, n) { | ||
;(t = t || 0), (n = n || 0) | ||
var r = new Date(0) | ||
r.setUTCFullYear(e, 0, 4) | ||
var a = 7 * t + n + 1 - (r.getUTCDay() || 7) | ||
return r.setUTCDate(r.getUTCDate() + a), r | ||
} | ||
var F = function(e, t) { | ||
if (a(e)) return new Date(e.getTime()) | ||
if ('string' != typeof e) return new Date(e) | ||
var n = (t || {}).additionalDigits | ||
n = null == n ? i : Number(n) | ||
var F = (function(e) { | ||
var t, | ||
n = {}, | ||
r = e.split(s) | ||
if ((c.test(r[0]) ? ((n.date = null), (t = r[0])) : ((n.date = r[0]), (t = r[1])), t)) { | ||
var a = p.exec(t) | ||
a ? ((n.time = t.replace(a[1], '')), (n.timezone = a[1])) : (n.time = t) | ||
} | ||
return n | ||
})(e), | ||
B = (function(e, t) { | ||
var n, | ||
r = D[t], | ||
a = l[t] | ||
if ((n = d.exec(e) || a.exec(e))) { | ||
var o = n[1] | ||
return {year: parseInt(o, 10), restDateString: e.slice(o.length)} | ||
} | ||
if ((n = f.exec(e) || r.exec(e))) { | ||
var u = n[1] | ||
return {year: 100 * parseInt(u, 10), restDateString: e.slice(u.length)} | ||
} | ||
return {year: null} | ||
})(F.date, n), | ||
b = B.year, | ||
H = (function(e, t) { | ||
if (null === t) return null | ||
var n, r, a, o | ||
if (0 === e.length) return (r = new Date(0)).setUTCFullYear(t), r | ||
if ((n = g.exec(e))) | ||
return (r = new Date(0)), (a = parseInt(n[1], 10) - 1), r.setUTCFullYear(t, a), r | ||
if ((n = m.exec(e))) { | ||
r = new Date(0) | ||
var u = parseInt(n[1], 10) | ||
return r.setUTCFullYear(t, 0, u), r | ||
} | ||
if ((n = v.exec(e))) { | ||
;(r = new Date(0)), (a = parseInt(n[1], 10) - 1) | ||
var i = parseInt(n[2], 10) | ||
return r.setUTCFullYear(t, a, i), r | ||
} | ||
if ((n = h.exec(e))) return (o = parseInt(n[1], 10) - 1), x(t, o) | ||
if ((n = y.exec(e))) { | ||
o = parseInt(n[1], 10) - 1 | ||
var s = parseInt(n[2], 10) - 1 | ||
return x(t, o, s) | ||
} | ||
return null | ||
})(B.restDateString, b) | ||
if (H) { | ||
var I, | ||
O = H.getTime(), | ||
$ = 0 | ||
if ( | ||
(F.time && | ||
($ = (function(e) { | ||
var t, n, r | ||
if ((t = M.exec(e))) return ((n = parseFloat(t[1].replace(',', '.'))) % 24) * o | ||
if ((t = k.exec(e))) | ||
return ( | ||
(n = parseInt(t[1], 10)), | ||
(r = parseFloat(t[2].replace(',', '.'))), | ||
(n % 24) * o + r * u | ||
) | ||
if ((t = T.exec(e))) { | ||
;(n = parseInt(t[1], 10)), (r = parseInt(t[2], 10)) | ||
var a = parseFloat(t[3].replace(',', '.')) | ||
return (n % 24) * o + r * u + 1e3 * a | ||
} | ||
return null | ||
})(F.time)), | ||
F.timezone) | ||
) | ||
(N = F.timezone), | ||
(I = | ||
((z = S.exec(N)) | ||
? 0 | ||
: (z = Y.exec(N)) | ||
? ((C = 60 * parseInt(z[2], 10)), '+' === z[1] ? -C : C) | ||
: (z = w.exec(N)) | ||
? ((C = 60 * parseInt(z[2], 10) + parseInt(z[3], 10)), '+' === z[1] ? -C : C) | ||
: 0) * u) | ||
else { | ||
var W = O + $, | ||
A = new Date(W) | ||
I = r(A) | ||
var G = new Date(W) | ||
G.setDate(A.getDate() + 1) | ||
var E = r(G) - r(A) | ||
E > 0 && (I += E) | ||
} | ||
return new Date(O + $ + I) | ||
} | ||
var N, z, C | ||
return new Date(e) | ||
} | ||
var B = function(e) { | ||
var t = F(e), | ||
n = new Date(0) | ||
return n.setFullYear(t.getFullYear(), 0, 1), n.setHours(0, 0, 0, 0), n | ||
} | ||
var b = function(e) { | ||
var t = F(e) | ||
return t.setHours(0, 0, 0, 0), t | ||
}, | ||
H = 6e4, | ||
I = 864e5 | ||
var O = function(e, t) { | ||
var n = b(e), | ||
r = b(t), | ||
a = n.getTime() - n.getTimezoneOffset() * H, | ||
o = r.getTime() - r.getTimezoneOffset() * H | ||
return Math.round((a - o) / I) | ||
} | ||
var $ = function(e) { | ||
var t = F(e) | ||
return O(t, B(t)) + 1 | ||
} | ||
var W = function(e, t) { | ||
var n = (t && Number(t.weekStartsOn)) || 0, | ||
r = F(e), | ||
a = r.getDay(), | ||
o = (a < n ? 7 : 0) + a - n | ||
return r.setDate(r.getDate() - o), r.setHours(0, 0, 0, 0), r | ||
} | ||
var A = function(e) { | ||
return W(e, {weekStartsOn: 1}) | ||
} | ||
var G = function(e) { | ||
var t = F(e), | ||
n = t.getFullYear(), | ||
r = new Date(0) | ||
r.setFullYear(n + 1, 0, 4), r.setHours(0, 0, 0, 0) | ||
var a = A(r), | ||
o = new Date(0) | ||
o.setFullYear(n, 0, 4), o.setHours(0, 0, 0, 0) | ||
var u = A(o) | ||
return t.getTime() >= a.getTime() ? n + 1 : t.getTime() >= u.getTime() ? n : n - 1 | ||
} | ||
var E = function(e) { | ||
var t = G(e), | ||
n = new Date(0) | ||
return n.setFullYear(t, 0, 4), n.setHours(0, 0, 0, 0), A(n) | ||
}, | ||
N = 6048e5 | ||
var z = function(e) { | ||
var t = F(e), | ||
n = A(t).getTime() - E(t).getTime() | ||
return Math.round(n / N) + 1 | ||
} | ||
var C = function(e) { | ||
if (a(e)) return !isNaN(e) | ||
throw new TypeError(toString.call(e) + ' is not an instance of Date') | ||
} | ||
var X = [ | ||
'M', | ||
'MM', | ||
'Q', | ||
'D', | ||
'DD', | ||
'DDD', | ||
'DDDD', | ||
'd', | ||
'E', | ||
'W', | ||
'WW', | ||
'YY', | ||
'YYYY', | ||
'GG', | ||
'GGGG', | ||
'H', | ||
'HH', | ||
'h', | ||
'hh', | ||
'm', | ||
'mm', | ||
's', | ||
'ss', | ||
'S', | ||
'SS', | ||
'SSS', | ||
'Z', | ||
'ZZ', | ||
'X', | ||
'x', | ||
] | ||
var Z = function(e) { | ||
var t = [] | ||
for (var n in e) e.hasOwnProperty(n) && t.push(n) | ||
var r = X.concat(t) | ||
.sort() | ||
.reverse() | ||
return new RegExp('(\\[[^\\[]*\\])|(\\\\)?(' + r.join('|') + '|.)', 'g') | ||
} | ||
var U = function() { | ||
var e = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], | ||
t = [ | ||
'January', | ||
'February', | ||
'March', | ||
'April', | ||
'May', | ||
'June', | ||
'July', | ||
'August', | ||
'September', | ||
'October', | ||
'November', | ||
'December', | ||
], | ||
n = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], | ||
r = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], | ||
a = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], | ||
o = ['AM', 'PM'], | ||
u = ['am', 'pm'], | ||
i = ['a.m.', 'p.m.'], | ||
s = { | ||
MMM: function(t) { | ||
return e[t.getMonth()] | ||
}, | ||
MMMM: function(e) { | ||
return t[e.getMonth()] | ||
}, | ||
dd: function(e) { | ||
return n[e.getDay()] | ||
}, | ||
ddd: function(e) { | ||
return r[e.getDay()] | ||
}, | ||
dddd: function(e) { | ||
return a[e.getDay()] | ||
}, | ||
A: function(e) { | ||
return e.getHours() / 12 >= 1 ? o[1] : o[0] | ||
}, | ||
a: function(e) { | ||
return e.getHours() / 12 >= 1 ? u[1] : u[0] | ||
}, | ||
aa: function(e) { | ||
return e.getHours() / 12 >= 1 ? i[1] : i[0] | ||
}, | ||
} | ||
return ( | ||
['M', 'D', 'DDD', 'd', 'Q', 'W'].forEach(function(e) { | ||
s[e + 'o'] = function(t, n) { | ||
return (function(e) { | ||
var t = e % 100 | ||
if (t > 20 || t < 10) | ||
switch (t % 10) { | ||
case 1: | ||
return e + 'st' | ||
case 2: | ||
return e + 'nd' | ||
case 3: | ||
return e + 'rd' | ||
} | ||
return e + 'th' | ||
})(n[e](t)) | ||
} | ||
}), | ||
{formatters: s, formattingTokensRegExp: Z(s)} | ||
) | ||
}, | ||
J = { | ||
distanceInWords: (function() { | ||
var e = { | ||
lessThanXSeconds: {one: 'less than a second', other: 'less than {{count}} seconds'}, | ||
xSeconds: {one: '1 second', other: '{{count}} seconds'}, | ||
halfAMinute: 'half a minute', | ||
lessThanXMinutes: {one: 'less than a minute', other: 'less than {{count}} minutes'}, | ||
xMinutes: {one: '1 minute', other: '{{count}} minutes'}, | ||
aboutXHours: {one: 'about 1 hour', other: 'about {{count}} hours'}, | ||
xHours: {one: '1 hour', other: '{{count}} hours'}, | ||
xDays: {one: '1 day', other: '{{count}} days'}, | ||
aboutXMonths: {one: 'about 1 month', other: 'about {{count}} months'}, | ||
xMonths: {one: '1 month', other: '{{count}} months'}, | ||
aboutXYears: {one: 'about 1 year', other: 'about {{count}} years'}, | ||
xYears: {one: '1 year', other: '{{count}} years'}, | ||
overXYears: {one: 'over 1 year', other: 'over {{count}} years'}, | ||
almostXYears: {one: 'almost 1 year', other: 'almost {{count}} years'}, | ||
} | ||
return { | ||
localize: function(t, n, r) { | ||
var a | ||
return ( | ||
(r = r || {}), | ||
(a = | ||
'string' == typeof e[t] | ||
? e[t] | ||
: 1 === n | ||
? e[t].one | ||
: e[t].other.replace('{{count}}', n)), | ||
r.addSuffix ? (r.comparison > 0 ? 'in ' + a : a + ' ago') : a | ||
) | ||
}, | ||
} | ||
})(), | ||
format: U(), | ||
} | ||
var R = { | ||
M: function(e) { | ||
return e.getMonth() + 1 | ||
}, | ||
MM: function(e) { | ||
return P(e.getMonth() + 1, 2) | ||
}, | ||
Q: function(e) { | ||
return Math.ceil((e.getMonth() + 1) / 3) | ||
}, | ||
D: function(e) { | ||
return e.getDate() | ||
}, | ||
DD: function(e) { | ||
return P(e.getDate(), 2) | ||
}, | ||
DDD: function(e) { | ||
return $(e) | ||
}, | ||
DDDD: function(e) { | ||
return P($(e), 3) | ||
}, | ||
d: function(e) { | ||
return e.getDay() | ||
}, | ||
E: function(e) { | ||
return e.getDay() || 7 | ||
}, | ||
W: function(e) { | ||
return z(e) | ||
}, | ||
WW: function(e) { | ||
return P(z(e), 2) | ||
}, | ||
YY: function(e) { | ||
return P(e.getFullYear(), 4).substr(2) | ||
}, | ||
YYYY: function(e) { | ||
return P(e.getFullYear(), 4) | ||
}, | ||
GG: function(e) { | ||
return String(G(e)).substr(2) | ||
}, | ||
GGGG: function(e) { | ||
return G(e) | ||
}, | ||
H: function(e) { | ||
return e.getHours() | ||
}, | ||
HH: function(e) { | ||
return P(e.getHours(), 2) | ||
}, | ||
h: function(e) { | ||
var t = e.getHours() | ||
return 0 === t ? 12 : t > 12 ? t % 12 : t | ||
}, | ||
hh: function(e) { | ||
return P(R.h(e), 2) | ||
}, | ||
m: function(e) { | ||
return e.getMinutes() | ||
}, | ||
mm: function(e) { | ||
return P(e.getMinutes(), 2) | ||
}, | ||
s: function(e) { | ||
return e.getSeconds() | ||
}, | ||
ss: function(e) { | ||
return P(e.getSeconds(), 2) | ||
}, | ||
S: function(e) { | ||
return Math.floor(e.getMilliseconds() / 100) | ||
}, | ||
SS: function(e) { | ||
return P(Math.floor(e.getMilliseconds() / 10), 2) | ||
}, | ||
SSS: function(e) { | ||
return P(e.getMilliseconds(), 3) | ||
}, | ||
Z: function(e) { | ||
return L(e.getTimezoneOffset(), ':') | ||
}, | ||
ZZ: function(e) { | ||
return L(e.getTimezoneOffset()) | ||
}, | ||
X: function(e) { | ||
return Math.floor(e.getTime() / 1e3) | ||
}, | ||
x: function(e) { | ||
return e.getTime() | ||
}, | ||
} | ||
function L(e, t) { | ||
t = t || '' | ||
var n = e > 0 ? '-' : '+', | ||
r = Math.abs(e), | ||
a = r % 60 | ||
return n + P(Math.floor(r / 60), 2) + t + P(a, 2) | ||
} | ||
function P(e, t) { | ||
for (var n = Math.abs(e).toString(); n.length < t; ) n = '0' + n | ||
return n | ||
} | ||
var Q = function(e, t, n) { | ||
var r = t ? String(t) : 'YYYY-MM-DDTHH:mm:ss.SSSZ', | ||
a = (n || {}).locale, | ||
o = J.format.formatters, | ||
u = J.format.formattingTokensRegExp | ||
a && | ||
a.format && | ||
a.format.formatters && | ||
((o = a.format.formatters), | ||
a.format.formattingTokensRegExp && (u = a.format.formattingTokensRegExp)) | ||
var i = F(e) | ||
return C(i) | ||
? (function(e, t, n) { | ||
var r, | ||
a, | ||
o, | ||
u = e.match(n), | ||
i = u.length | ||
for (r = 0; r < i; r++) | ||
(a = t[u[r]] || R[u[r]]), | ||
(u[r] = | ||
a || ((o = u[r]).match(/\[[\s\S]/) ? o.replace(/^\[|]$/g, '') : o.replace(/\\/g, ''))) | ||
return function(e) { | ||
for (var t = '', n = 0; n < i; n++) | ||
u[n] instanceof Function ? (t += u[n](e, R)) : (t += u[n]) | ||
return t | ||
} | ||
})(r, o, u)(i) | ||
: 'Invalid Date' | ||
} | ||
var j = function(e, t) { | ||
var n = F(e), | ||
r = Number(t) | ||
return n.setDate(n.getDate() + r), n | ||
} | ||
var q = function(e, t, n) { | ||
var r = F(e), | ||
a = void 0 !== n ? n : 1, | ||
o = F(t).getTime() | ||
if (r.getTime() > o) throw new Error('The first date cannot be after the second date') | ||
var u = [], | ||
i = r | ||
for (i.setHours(0, 0, 0, 0); i.getTime() <= o; ) u.push(F(i)), i.setDate(i.getDate() + a) | ||
return u | ||
} | ||
var K = function(e) { | ||
var t = F(e), | ||
n = t.getMonth() | ||
return t.setFullYear(t.getFullYear(), n + 1, 0), t.setHours(23, 59, 59, 999), t | ||
} | ||
var V = function(e, t) { | ||
var n = (t && Number(t.weekStartsOn)) || 0, | ||
r = F(e), | ||
a = r.getDay(), | ||
o = 6 + (a < n ? -7 : 0) - (a - n) | ||
return r.setDate(r.getDate() + o), r.setHours(23, 59, 59, 999), r | ||
} | ||
var _ = function(e) { | ||
return F(e).getDay() | ||
} | ||
var ee = function(e) { | ||
var t = F(e) | ||
return t.setDate(1), t.setHours(0, 0, 0, 0), t | ||
} | ||
function te(e) { | ||
var t = void 0 === e ? {} : e, | ||
n = t.weekStartsOn, | ||
r = void 0 === n ? 1 : n, | ||
a = t.weekDayFormat, | ||
o = | ||
void 0 === a | ||
? function(e) { | ||
return Q(e, 'dd') | ||
} | ||
: a, | ||
u = new Date() | ||
return q(j(W(u), r), j(V(u), r)).reduce(function(e, t) { | ||
return e.push(o(t)), e | ||
}, []) | ||
} | ||
function ne(e) { | ||
var t = e.year, | ||
n = e.month, | ||
r = e.weekStartsOn, | ||
a = void 0 === r ? 1 : r, | ||
o = e.dayFormat, | ||
u = | ||
void 0 === o | ||
? function(e) { | ||
return Q(e, 'DD') | ||
} | ||
: o, | ||
i = new Date(t, n), | ||
s = ee(i), | ||
c = _(s), | ||
f = K(i), | ||
D = Array.from(Array(c >= a ? c - a : a).keys()).fill(0), | ||
d = q(s, f).map(function(e) { | ||
return {date: e, day: u(e)} | ||
}) | ||
return D.concat(d) | ||
} | ||
function re(t) { | ||
var n = t.year, | ||
r = t.month, | ||
a = t.weekStartsOn, | ||
o = void 0 === a ? 1 : a, | ||
u = t.dayFormat, | ||
i = | ||
void 0 === u | ||
? function(e) { | ||
return Q(e, 'DD') | ||
} | ||
: u, | ||
s = t.weekDayFormat, | ||
c = | ||
void 0 === s | ||
? function(e) { | ||
return Q(e, 'dd') | ||
} | ||
: s, | ||
f = t.monthLabelFormat, | ||
D = | ||
void 0 === f | ||
? function(e) { | ||
return Q(e, 'MMMM YYYY') | ||
} | ||
: f | ||
return { | ||
days: e( | ||
function() { | ||
return ne({year: n, month: r, weekStartsOn: o, dayFormat: i}) | ||
}, | ||
[n, r, o, i], | ||
), | ||
weekDays: e( | ||
function() { | ||
return te({weekStartsOn: o, weekDayFormat: c}) | ||
}, | ||
[o, c], | ||
), | ||
monthLabel: D(new Date(n, r)), | ||
} | ||
} | ||
var ae = function(e, t) { | ||
var n = F(e), | ||
r = F(t) | ||
return n.getTime() < r.getTime() | ||
} | ||
var oe = function(e, t) { | ||
var n = F(e), | ||
r = F(t) | ||
return n.getTime() > r.getTime() | ||
} | ||
var ue = function(e, t, n) { | ||
var r = F(e).getTime(), | ||
a = F(t).getTime(), | ||
o = F(n).getTime() | ||
if (a > o) throw new Error('The start of the range cannot be after the end of the range') | ||
return r >= a && r <= o | ||
} | ||
var ie = function(e, t) { | ||
var n = b(e), | ||
r = b(t) | ||
return n.getTime() === r.getTime() | ||
} | ||
var se = function(e) { | ||
return F(e).getFullYear() | ||
} | ||
var ce = function(e) { | ||
return F(e).getMonth() | ||
} | ||
var fe = function() { | ||
return b(new Date()) | ||
} | ||
var De = function(e) { | ||
var t = F(e), | ||
n = t.getFullYear(), | ||
r = t.getMonth(), | ||
a = new Date(0) | ||
return a.setFullYear(n, r + 1, 0), a.setHours(0, 0, 0, 0), a.getDate() | ||
} | ||
var de = function(e, t) { | ||
var n = F(e), | ||
r = Number(t), | ||
a = n.getMonth() + r, | ||
o = new Date(0) | ||
o.setFullYear(n.getFullYear(), a, 1), o.setHours(0, 0, 0, 0) | ||
var u = De(o) | ||
return n.setMonth(a, Math.min(u, n.getDate())), n | ||
} | ||
function le(e, t, n) { | ||
return !(!t || !n) && ue(e, t, n) | ||
} | ||
function ge(e, t, n) { | ||
return !!((t && ie(e, t)) || (n && ie(e, n))) | ||
} | ||
function me(e) { | ||
var t = e.date, | ||
n = e.minBookingDate, | ||
r = e.maxBookingDate, | ||
a = e.isDayBlockedFn, | ||
o = e.startDate, | ||
u = e.endDate, | ||
i = e.minBookingDays, | ||
s = void 0 === i ? 1 : i, | ||
c = n ? new Date(n.getFullYear(), n.getMonth(), n.getDate(), 0, 0, 0) : n, | ||
f = r ? new Date(r.getFullYear(), r.getMonth(), r.getDate(), 0, 0, 0) : r | ||
return !!( | ||
(c && ae(t, c)) || | ||
(f && oe(t, f)) || | ||
(o && !u && s > 1 && ue(t, o, j(o, s - 2))) || | ||
(a && a(t)) | ||
) | ||
} | ||
function ve(e) { | ||
var t = ee(e) | ||
return {year: se(t), month: ce(t), date: t} | ||
} | ||
function he() { | ||
return ve(fe()) | ||
} | ||
function ye(e, t) { | ||
var n = t ? ve(t) : he(), | ||
r = n.date, | ||
a = [n] | ||
return ( | ||
e > 1 && | ||
(a = Array.from(Array(e - 1).keys()).reduce(function(e) { | ||
return (r = de(e[e.length - 1].date, 1)), e.concat([ve(r)]) | ||
}, a)), | ||
a | ||
) | ||
} | ||
function Me(e, t, n) { | ||
var r = e[n > 0 ? e.length - 1 : 0].date | ||
return Array.from(Array(t).keys()).reduce(function(e) { | ||
return (r = de(r, n)), n > 0 ? e.concat([ve(r)]) : [ve(r)].concat(e) | ||
}, []) | ||
} | ||
function ke(e, t, n) { | ||
return e && 'string' == typeof t ? Q(e, t) : e && 'function' == typeof t ? t(e) : n | ||
} | ||
function Te(e) { | ||
var t = e.startDate, | ||
n = e.endDate, | ||
r = e.isDateBlocked, | ||
a = e.minBookingDays, | ||
o = e.exactMinBookingDays, | ||
u = e.minBookingDate, | ||
i = e.maxBookingDate | ||
if (t && 1 === a && !n && !r(t)) return !0 | ||
if ( | ||
(t && a > 1 && !n && !o) || | ||
(t && a > 0 && o && u && i && !ae(t, u) && !oe(j(t, a - 1), i)) || | ||
(t && a > 0 && o && !u && !i) | ||
) | ||
return q(t, j(t, a - 1)).reduce(function(e, t) { | ||
return e ? !r(t) : e | ||
}, !0) | ||
if (t && n && !o) { | ||
var s = j(t, a - 1) | ||
return ( | ||
!ae(n, s) && | ||
q(t, n).reduce(function(e, t) { | ||
return e ? !r(t) : e | ||
}, !0) | ||
) | ||
} | ||
return !1 | ||
} | ||
var pe = 'startDate', | ||
Se = 'endDate' | ||
function Ye(e) { | ||
var r = e.startDate, | ||
a = e.endDate, | ||
o = e.focusedInput, | ||
u = e.minBookingDate, | ||
i = e.maxBookingDate, | ||
s = e.onDateChange, | ||
c = e.exactMinBookingDays, | ||
f = void 0 !== c && c, | ||
D = e.minBookingDays, | ||
d = void 0 === D ? 1 : D, | ||
l = e.numberOfMonths, | ||
g = void 0 === l ? 2 : l, | ||
m = e.firstDayOfWeek, | ||
v = void 0 === m ? 1 : m, | ||
h = e.isDayBlocked, | ||
y = | ||
void 0 === h | ||
? function() { | ||
return !1 | ||
} | ||
: h, | ||
M = t(function() { | ||
return ye(g, r) | ||
}), | ||
k = M[0], | ||
T = M[1], | ||
p = t(null), | ||
S = p[0], | ||
Y = p[1], | ||
w = n( | ||
function(e) { | ||
return le(e, r, a) | ||
}, | ||
[r, a], | ||
), | ||
x = n( | ||
function(e) { | ||
return ge(e, r, a) | ||
}, | ||
[r, a], | ||
), | ||
F = n( | ||
function(e) { | ||
return me({ | ||
date: e, | ||
minBookingDate: u, | ||
maxBookingDate: i, | ||
startDate: r, | ||
endDate: a, | ||
minBookingDays: d, | ||
isDayBlockedFn: y, | ||
}) | ||
}, | ||
[u, i, r, a, d, y], | ||
), | ||
B = n( | ||
function(e) { | ||
return (function(e) { | ||
var t = e.date, | ||
n = e.startDate, | ||
r = e.endDate, | ||
a = e.isDateBlocked, | ||
o = e.hoveredDate, | ||
u = e.minBookingDays, | ||
i = e.exactMinBookingDays | ||
return o && u > 1 && i && ue(t, o, j(o, u - 1)) | ||
? q(o, j(o, u - 1)).reduce(function(e, t) { | ||
return e ? !a(t) : e | ||
}, !0) | ||
: n && !r && o && ue(t, n, j(n, u - 1)) && ie(n, o) && u > 1 | ||
? q(n, j(n, u - 1)).reduce(function(e, t) { | ||
return e ? !a(t) : e | ||
}, !0) | ||
: !(!n || r || !o || ae(o, n) || !ue(t, n, o)) && | ||
q(n, o).reduce(function(e, t) { | ||
return e ? !a(t) : e | ||
}, !0) | ||
})({ | ||
date: e, | ||
hoveredDate: S, | ||
startDate: r, | ||
endDate: a, | ||
minBookingDays: d, | ||
exactMinBookingDays: f, | ||
isDateBlocked: y, | ||
}) | ||
}, | ||
[S, r, a, d, f, y], | ||
) | ||
return { | ||
firstDayOfWeek: v, | ||
activeMonths: k, | ||
isDateSelected: w, | ||
isDateHovered: B, | ||
isFirstOrLastSelectedDate: x, | ||
isDateBlocked: F, | ||
numberOfMonths: g, | ||
onResetDates: function() { | ||
s({startDate: null, endDate: null, focusedInput: pe}) | ||
}, | ||
onDayHover: function(e) { | ||
;(f && (d <= 1 || (u && i && (!ue(e, u, i) || !ue(j(e, d - 1), u, i))))) || | ||
(!f && | ||
(!r || a || (u && i && !ue(e, u, i)) || (!ie(e, r) && d > 1 && r && ue(e, r, j(r, d - 2))))) | ||
? Y(null) | ||
: Y(e) | ||
}, | ||
onDaySelect: function(e) { | ||
;(o === Se || o === pe) && | ||
d > 0 && | ||
f && | ||
Te({ | ||
minBookingDays: d, | ||
exactMinBookingDays: f, | ||
minBookingDate: u, | ||
maxBookingDate: i, | ||
isDateBlocked: y, | ||
startDate: e, | ||
endDate: null, | ||
}) | ||
? s({startDate: e, endDate: j(e, d - 1), focusedInput: null}) | ||
: ((o === Se && r && ae(e, r)) || (o === pe && a && oe(e, a))) && | ||
!f && | ||
Te({minBookingDays: d, isDateBlocked: y, startDate: e, endDate: null}) | ||
? s({endDate: null, startDate: e, focusedInput: Se}) | ||
: o === pe && !f && Te({minBookingDays: d, isDateBlocked: y, endDate: a, startDate: e}) | ||
? s({endDate: a, startDate: e, focusedInput: Se}) | ||
: o === pe && !f && Te({minBookingDays: d, isDateBlocked: y, endDate: null, startDate: e}) | ||
? s({endDate: null, startDate: e, focusedInput: Se}) | ||
: o === Se && | ||
r && | ||
!ae(e, r) && | ||
!f && | ||
Te({minBookingDays: d, isDateBlocked: y, startDate: r, endDate: e}) && | ||
s({startDate: r, endDate: e, focusedInput: null}) | ||
}, | ||
goToPreviousMonths: function() { | ||
T(Me(k, g, -1)) | ||
}, | ||
goToNextMonths: function() { | ||
T(Me(k, g, 1)) | ||
}, | ||
} | ||
} | ||
export { | ||
Se as END_DATE, | ||
pe as START_DATE, | ||
he as getCurrentYearMonthAndDate, | ||
ve as getDateMonthAndYear, | ||
ne as getDays, | ||
ye as getInitialMonths, | ||
ke as getInputValue, | ||
te as getWeekDays, | ||
me as isDateBlocked, | ||
le as isDateSelected, | ||
ge as isFirstOrLastSelectedDate, | ||
Ye as useDatepicker, | ||
re as useMonth, | ||
} |
@@ -1,3 +0,44 @@ | ||
import { useDatepicker, UseDatepickerProps, END_DATE, START_DATE, FocusedInput, FirstDayOfWeek, OnDateChange } from './useDatepicker'; | ||
import { isDateSelected, isStartOrEndDate, isDateBlocked, getCurrentYearMonthAndDate, getDateMonthAndYear, getInitialMonths, getInputValue, getNextActiveMonth, FormatFunction, MonthType } from './useDatepicker.utils'; | ||
export { useDatepicker, isDateSelected, isStartOrEndDate, isDateBlocked, getCurrentYearMonthAndDate, getDateMonthAndYear, getInitialMonths, getInputValue, getNextActiveMonth, FormatFunction, MonthType, UseDatepickerProps, END_DATE, START_DATE, FocusedInput, FirstDayOfWeek, OnDateChange, }; | ||
import { | ||
useDatepicker, | ||
UseDatepickerProps, | ||
END_DATE, | ||
START_DATE, | ||
FocusedInput, | ||
FirstDayOfWeek, | ||
OnDateChange, | ||
} from './useDatepicker' | ||
import { | ||
isDateSelected, | ||
isFirstOrLastSelectedDate, | ||
isDateBlocked, | ||
getCurrentYearMonthAndDate, | ||
getDateMonthAndYear, | ||
getInitialMonths, | ||
getInputValue, | ||
getNextActiveMonth, | ||
FormatFunction, | ||
MonthType, | ||
canSelectRange, | ||
isDateHovered, | ||
} from './useDatepicker.utils' | ||
export { | ||
useDatepicker, | ||
isDateSelected, | ||
isFirstOrLastSelectedDate, | ||
isDateBlocked, | ||
getCurrentYearMonthAndDate, | ||
getDateMonthAndYear, | ||
getInitialMonths, | ||
getInputValue, | ||
getNextActiveMonth, | ||
canSelectRange, | ||
isDateHovered, | ||
FormatFunction, | ||
MonthType, | ||
UseDatepickerProps, | ||
END_DATE, | ||
START_DATE, | ||
FocusedInput, | ||
FirstDayOfWeek, | ||
OnDateChange, | ||
} |
@@ -1,34 +0,50 @@ | ||
import { MonthType } from './useDatepicker.utils'; | ||
export declare const START_DATE = "startDate"; | ||
export declare const END_DATE = "endDate"; | ||
export declare type FocusedInput = 'startDate' | 'endDate' | null; | ||
import {MonthType} from './useDatepicker.utils' | ||
export declare const START_DATE = 'startDate' | ||
export declare const END_DATE = 'endDate' | ||
export declare type FocusedInput = 'startDate' | 'endDate' | null | ||
export interface OnDateChange { | ||
focusedInput: FocusedInput; | ||
startDate: Date | null; | ||
endDate: Date | null; | ||
focusedInput: FocusedInput | ||
startDate: Date | null | ||
endDate: Date | null | ||
} | ||
export declare type FirstDayOfWeek = 0 | 1 | 2 | 3 | 4 | 5 | 6; | ||
export declare type FirstDayOfWeek = 0 | 1 | 2 | 3 | 4 | 5 | 6 | ||
export interface UseDatepickerProps { | ||
onDateChange(data: OnDateChange): void; | ||
minBookingDate?: Date; | ||
maxBookingDate?: Date; | ||
startDate: Date | null; | ||
endDate: Date | null; | ||
focusedInput: FocusedInput; | ||
orientation?: 'horizontal' | 'vertical'; | ||
numberOfMonths?: number; | ||
firstDayOfWeek?: FirstDayOfWeek; | ||
initialVisibleMonth?(numberOfMonths: number): MonthType[]; | ||
onDateChange(data: OnDateChange): void | ||
minBookingDate?: Date | ||
maxBookingDate?: Date | ||
startDate: Date | null | ||
endDate: Date | null | ||
focusedInput: FocusedInput | ||
numberOfMonths?: number | ||
minBookingDays?: number | ||
exactMinBookingDays?: boolean | ||
firstDayOfWeek?: FirstDayOfWeek | ||
initialVisibleMonth?(numberOfMonths: number): MonthType[] | ||
isDayBlocked?(date: Date): boolean | ||
} | ||
export declare function useDatepicker({ startDate, endDate, focusedInput, minBookingDate, maxBookingDate, onDateChange, numberOfMonths, firstDayOfWeek, }: UseDatepickerProps): { | ||
firstDayOfWeek: FirstDayOfWeek; | ||
activeMonths: MonthType[]; | ||
isDateSelected: (date: Date) => boolean; | ||
isStartOrEndDate: (date: Date) => boolean; | ||
isDateBlocked: (date: Date) => boolean; | ||
numberOfMonths: number; | ||
onResetDates: () => void; | ||
onDaySelect: (date: Date) => void; | ||
goToPreviousMonths: () => void; | ||
goToNextMonths: () => void; | ||
}; | ||
export declare function useDatepicker({ | ||
startDate, | ||
endDate, | ||
focusedInput, | ||
minBookingDate, | ||
maxBookingDate, | ||
onDateChange, | ||
exactMinBookingDays, | ||
minBookingDays, | ||
numberOfMonths, | ||
firstDayOfWeek, | ||
isDayBlocked: isDayBlockedProps, | ||
}: UseDatepickerProps): { | ||
firstDayOfWeek: FirstDayOfWeek | ||
activeMonths: MonthType[] | ||
isDateSelected: (date: Date) => boolean | ||
isDateHovered: (date: Date) => boolean | ||
isFirstOrLastSelectedDate: (date: Date) => boolean | ||
isDateBlocked: (date: Date) => boolean | ||
numberOfMonths: number | ||
onResetDates: () => void | ||
onDayHover: (date: Date) => void | ||
onDaySelect: (date: Date) => void | ||
goToPreviousMonths: () => void | ||
goToNextMonths: () => void | ||
} |
@@ -1,14 +0,87 @@ | ||
export declare function isDateSelected(date: Date, startDate: Date | null, endDate: Date | null): boolean; | ||
export declare function isStartOrEndDate(date: Date, startDate: Date | null, endDate: Date | null): boolean; | ||
export declare function isDateBlocked(date: Date, minBookingDate?: Date, maxBookingDate?: Date, isDayBlockedFn?: (date?: Date) => boolean): boolean; | ||
export declare function isDateSelected( | ||
date: Date, | ||
startDate: Date | null, | ||
endDate: Date | null, | ||
): boolean | ||
export declare function isFirstOrLastSelectedDate( | ||
date: Date, | ||
startDate: Date | null, | ||
endDate: Date | null, | ||
): boolean | ||
interface IsDateBlockedProps { | ||
date: Date | ||
startDate: Date | null | ||
endDate: Date | null | ||
minBookingDays?: number | ||
minBookingDate?: Date | ||
maxBookingDate?: Date | ||
isDayBlockedFn?: (date?: Date) => boolean | ||
} | ||
export declare function isDateBlocked({ | ||
date, | ||
minBookingDate, | ||
maxBookingDate, | ||
isDayBlockedFn, | ||
startDate, | ||
endDate, | ||
minBookingDays, | ||
}: IsDateBlockedProps): boolean | ||
export interface MonthType { | ||
year: number; | ||
month: number; | ||
date: Date; | ||
year: number | ||
month: number | ||
date: Date | ||
} | ||
export declare function getDateMonthAndYear(date: Date): MonthType; | ||
export declare function getCurrentYearMonthAndDate(): MonthType; | ||
export declare function getInitialMonths(numberOfMonths: number, startDate: Date | null): MonthType[]; | ||
export declare function getNextActiveMonth(activeMonth: MonthType[], numberOfMonths: number, counter: number): MonthType[]; | ||
export declare type FormatFunction = (date: Date) => string; | ||
export declare function getInputValue(date: Date | null, displayFormat: string | FormatFunction, defaultValue: string): string; | ||
export declare function getDateMonthAndYear(date: Date): MonthType | ||
export declare function getCurrentYearMonthAndDate(): MonthType | ||
export declare function getInitialMonths( | ||
numberOfMonths: number, | ||
startDate: Date | null, | ||
): MonthType[] | ||
export declare function getNextActiveMonth( | ||
activeMonth: MonthType[], | ||
numberOfMonths: number, | ||
counter: number, | ||
): MonthType[] | ||
export declare type FormatFunction = (date: Date) => string | ||
export declare function getInputValue( | ||
date: Date | null, | ||
displayFormat: string | FormatFunction, | ||
defaultValue: string, | ||
): string | ||
export interface CanSelectRangeProps { | ||
startDate: Date | ||
endDate: Date | null | ||
isDateBlocked(date: Date): boolean | ||
minBookingDays: number | ||
exactMinBookingDays?: boolean | ||
minBookingDate?: Date | ||
maxBookingDate?: Date | ||
} | ||
export declare function canSelectRange({ | ||
startDate, | ||
endDate, | ||
isDateBlocked, | ||
minBookingDays, | ||
exactMinBookingDays, | ||
minBookingDate, | ||
maxBookingDate, | ||
}: CanSelectRangeProps): boolean | ||
export interface IsDateHoveredProps { | ||
startDate: Date | null | ||
endDate: Date | null | ||
date: Date | ||
isDateBlocked(date: Date): boolean | ||
hoveredDate: Date | null | ||
minBookingDays: number | ||
exactMinBookingDays: boolean | ||
} | ||
export declare function isDateHovered({ | ||
date, | ||
startDate, | ||
endDate, | ||
isDateBlocked, | ||
hoveredDate, | ||
minBookingDays, | ||
exactMinBookingDays, | ||
}: IsDateHoveredProps): boolean | ||
export {} |
{ | ||
"name": "@datepicker-react/hooks", | ||
"version": "1.2.2-alpha.0", | ||
"version": "1.2.3-alpha.0", | ||
"description": "React hooks for datepicker.", | ||
@@ -46,3 +46,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "f1636b8ef5cd1445607afde1befb5d687dec03ea" | ||
"gitHead": "5aba27d6427edee207845e8bed46f6a0a657d71d" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
58233
2027
2
1