@shonum/tailwind-datepicker-react
Version:
A tailwindcss/flowbite datepicker component built as a react component with types
1 lines • 2.3 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:all[name]})}_export(exports,{firstDateOfMonth:function(){return firstDateOfMonth},addDays:function(){return addDays},dayDiff:function(){return dayDiff},dayOfTheWeekOf:function(){return dayOfTheWeekOf},addMonths:function(){return addMonths},addYears:function(){return addYears},getFormattedDate:function(){return getFormattedDate},goToPrevNext:function(){return goToPrevNext},startOfYearPeriod:function(){return startOfYearPeriod}});var firstDateOfMonth=function(selectedYear,selectedMonth,date){var newDate=new Date(0);newDate.setFullYear(selectedYear,selectedMonth,date);return newDate.setHours(0,0,0,0)};var addDays=function(date,amount){var newDate=new Date(date);return newDate.setDate(newDate.getDate()+amount)};var dayDiff=function(day,from){return(day-from+7)%7};var dayOfTheWeekOf=function(baseDate,dayOfWeek){var weekStart=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0;var baseDay=new Date(baseDate).getDay();return addDays(baseDate,dayDiff(dayOfWeek,weekStart)-dayDiff(baseDay,weekStart))};var addMonths=function(date,amount){var newDate=date;var monthsToSet=newDate.getMonth()+amount;var expectedMonth=monthsToSet%12;if(expectedMonth<0){expectedMonth+=12}var time=newDate.setMonth(monthsToSet);return newDate.getMonth()!==expectedMonth?newDate.setDate(0):time};var addYears=function(date,amount){var newDate=date;var expectedMonth=newDate.getMonth();var time=newDate.setFullYear(newDate.getFullYear()+amount);return expectedMonth===1&&newDate.getMonth()===2?newDate.setDate(0):time};var getFormattedDate=function(language,date,options){var defaultOptions={day:"numeric",month:"long",year:"numeric"};if(options)defaultOptions=options;return new Intl.DateTimeFormat(language,defaultOptions).format(date)};var goToPrevNext=function(view,date,direction){switch(view){case"days":return addMonths(date,direction);case"months":return addYears(date,direction);case"years":return addYears(date,direction*10);case"decades":return addYears(date,direction*100);default:return addYears(date,direction*10)}};var startOfYearPeriod=function(date,years){var year=date.getFullYear();return Math.floor(year/years)*years};