From 8d1a5e5626bb884c2f6322074fbb9600f7c81c96 Mon Sep 17 00:00:00 2001 From: AnuzPandey Date: Sun, 29 Oct 2023 20:15:07 +0545 Subject: [PATCH] :zap: features: add source files. --- public/css/nepali-date-picker.min.css | 1 + public/js/nepali-date-picker.min.js | 39 ++++++++++ readme.md | 101 ++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 public/css/nepali-date-picker.min.css create mode 100644 public/js/nepali-date-picker.min.js create mode 100644 readme.md diff --git a/public/css/nepali-date-picker.min.css b/public/css/nepali-date-picker.min.css new file mode 100644 index 0000000..ddf2c3f --- /dev/null +++ b/public/css/nepali-date-picker.min.css @@ -0,0 +1 @@ +@import url(https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap);:root{--ap-white:#ffffff;--ap-black:#000000;--rounded-md:0.375rem;--gray-50:rgb(249 250 251 / 1);--gray-100:rgb(243 244 246 / 1);--gray-200:rgb(229 231 235 / 1);--gray-300:rgb(209 213 219 / 1);--gray-400:rgb(156 163 175 / 1);--gray-500:rgb(107 114 128 / 1);--gray-600:rgb(75 85 99 / 1);--gray-700:rgb(55 65 81 / 1);--gray-800:rgb(31 41 55 / 1);--gray-900:rgb(17 24 39 / 1);--gray-950:rgb(3 7 18 / 1);--red-400:rgb(248 113 113 / 1);--red-500:rgb(239 68 68 / 1)}.theme-dark{--ap-white:#1D1D1D;--ap-black:#fefefe;--gray-50:rgb(3 7 18 / 1);--gray-100:rgb(33 34 36 / 1);--gray-200:rgb(31 41 55 / 1);--gray-300:rgb(55 65 81 / 1);--gray-400:rgb(75 85 99 / 1 );--gray-500:rgb(210 210 210 / 1);--gray-600:rgb(156 163 175 / 1);--gray-700:rgb(209 213 219 / 1);--gray-800:rgb(229 231 235 / 1);--gray-900:rgb(243 244 246 / 1);--gray-950:rgb(249 250 251 / 1);--red-400:rgb(248 113 113 / 1);--red-500:rgb(239 68 68 / 1)}.ap-card{font-family:"Inter",sans-serif;z-index:10;position:absolute;display:none;width:auto;max-width:fit-content;background:var(--ap-white);box-shadow:0 0#0000,0 0#0000,0 1px 2px 0 rgb(0 0 0/.05);padding:.5rem;box-sizing:border-box;font-size:.875rem;line-height:1.25rem;border:1px solid rgb(229 231 235/1);border-radius:var(--rounded-md);margin-top:.25rem}.ap-header-wrapper{display:flex;justify-content:space-between;align-items:center;width:100%}.ap-header__button{padding:.25rem;border-radius:var(--rounded-md);color:var(--ap-black);transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:150ms;width:2.5rem;height:2.5rem;display:flex;justify-content:center;align-items:center;border:0;background:var(--ap-white)}.ap-header__button:hover{color:var(--gray-600);background:var(--gray-100)}.ap-header__button:focus{color:var(--ap-black);background:var(--ap-white);outline:0}.ap-header__button>svg{width:1.25rem;height:1.25rem}.ap-header__selects{display:flex;align-items:center;gap:.25rem}.ap-header__select{appearance:none;line-height:1.8;text-align:center;height:2.5rem;padding:.25rem 1rem;border-radius:var(--rounded-md);border:0;background:var(--ap-white);color:var(--ap-black)}.ap-header__select:focus{outline:0}.ap-header__select:hover{background:var(--gray-100)}.ap-table{margin-top:.5rem;text-align:center;width:100%}.ap-table__thead__tr{padding-top:.5rem;padding-bottom:.75rem}.ap-table__tbody__tr,.ap-table__thead__tr{display:flex;flex-wrap:nowrap;align-items:center;justify-content:flex-start;color:var(--gray-500);gap:.25rem}.ap-table__thead__tr_th{width:2.5rem;font-weight:500;padding:0}.holiday-marker-color{color:var(--red-400)!important}.holiday-marker-color:hover>button{color:var(--red-500)!important}.ap-table__tbody{display:flex;flex-direction:column;row-gap:.25rem}.ap-table__thead__tr_td{height:2.5rem;width:2.5rem;text-align:center;padding:0;position:relative;color:var(--gray-500)}.ap-table__thead__tr_td>button{display:inline-flex;align-items:center;justify-content:center;border-radius:var(--rounded-md);transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:150ms;width:2.5rem;height:2.5rem;padding:0;font-weight:400;border:0;background:var(--ap-white);color:inherit}.ap-table__thead__tr_td>button:focus{outline:0}.ap-table__thead__tr_td>button:disabled{color:var(--gray-400);background:var(--gray-100);cursor:not-allowed}.ap-table__thead__tr_td>button:hover{color:var(--gray-500);background:var(--gray-100)}.no-hover:hover{color:transparent!important;background:0 0!important}.pointer-events-none{pointer-events:none}.bordered{border:1px solid var(--gray-200)}.ap-width-tr-td{width:2.5rem}.ap-width-ddd{width:4rem}.ap-width-np-ddd{width:5rem}.ap-gap{gap:.25rem}.ap-table__thead__tr_td>button.selected{background:var(--ap-black)!important;color:var(--ap-white)!important;border:0!important}.ap-cell-button.selected:hover{background:var(--gray-800);color:var(--ap-white)}.bordered-theme{border:1px solid var(--gray-200)!important}.soft-theme{background:var(--gray-50)!important;transition:all ease}.soft-theme:hover{background:var(--gray-100)!important}.bordered-dashed{border-style:dashed!important}.ap-table__thead__tr_td.active>button{background:var(--gray-100);border:1px dashed var(--gray-400)!important}.ap-position-left{left:0}.ap-position-right{right:0!important}.ap-position-center{left:0!important;right:0!important;margin-left:auto!important;margin-right:auto!important} \ No newline at end of file diff --git a/public/js/nepali-date-picker.min.js b/public/js/nepali-date-picker.min.js new file mode 100644 index 0000000..0e24aa1 --- /dev/null +++ b/public/js/nepali-date-picker.min.js @@ -0,0 +1,39 @@ +class NepaliDatePicker{constructor(config){this.today=new Date,this.currentYear=this.today.getFullYear(),this.currentMonth=this.today.getMonth(),this.currentDay=this.today.getDate(),this.triggerDataAttributeLabel="data-nepali-date-picker",this.options={format:"YYYY-MM-DD",closeOnDateSelect:!0,disableAfterToday:!1,disableBeforeToday:!1,disableToday:!1,markHolidays:!0,holidays:["Saturday"],indicateCurrentDate:!0,setCurrentDate:!1,position:"left",daysFormat:"dd",locale:"np",theme:"flat",darkMode:!1},"object"==typeof config&&(this.options={...this.options,...config}),this.dynamicClassValues={trGap:"ap-gap",trAndTdWidth:"ddd"===this.options.daysFormat?"np"===this.options.locale?"ap-width-np-ddd":"ap-width-ddd":"ap-width-tr-td",position:this.getPositionClasses()},this.init()}init(setCurrentDate=!0){setCurrentDate&&this.setCurrentDate(),this.setupTriggers(),this.setupOpeners(),this.setupClosers()}setCurrentDate(){var{year,month,date}=this.convertToNepaliDate(this.currentYear,this.currentMonth+1,this.currentDay);this.currentYear=+year,this.currentMonth=+month,this.currentDay=+date}setupTriggers(){this.setupInputTriggers(),this.setupInputFieldConfiguration(),this.setupCellButtonClickTriggers()}setupInputFieldConfiguration(){}setupCellButtonClickTriggers(){document.addEventListener("click",event=>{if(event.preventDefault(),event.target.classList.contains("ap-cell-button")){document.querySelectorAll(".ap-cell-button");const parentTable=event.target.closest("table"),apCells=parentTable.querySelectorAll(".ap-cell-button");apCells.forEach(function(apCell){apCell&&"selected".split(" ").forEach(className=>apCell.classList.remove(className))}),"selected".split(" ").forEach(className=>event.target.classList.add(className));var currentYear=parseInt(event.target.closest(".ap-card").querySelector(".ap-calendar-year").value),showMonth=parseInt(event.target.closest(".ap-card").querySelector(".ap-calendar-month").value)+1,value=this.decodeUnicodeToEnglishText(event.target.textContent),showMonth=("0"+showMonth).slice(-2),value=("0"+value).slice(-2),value=this.getFormattedDate(currentYear,showMonth,value);let apCalendar=event.target.closest(".ap-card").previousElementSibling;if(apCalendar&&(apCalendar.value=value),this.options.closeOnDateSelect){const apCards=document.querySelectorAll(".ap-card");apCards.forEach(function(apCard){apCard.style.display="none"})}}})}setupInputTriggers(){const triggers=document.querySelectorAll(`[${this.triggerDataAttributeLabel}]`);0{this.options.setCurrentDate&&(trigger.value=this.getFormattedDate(this.currentYear,this.currentMonth+1,this.currentDay)),trigger.hasAttribute("placeholder")||trigger.setAttribute("placeholder",this.options.format),trigger.addEventListener("click",event=>{event.preventDefault();const nextSibling=event.target.nextElementSibling;nextSibling&&nextSibling.classList.contains("ap-card")||this.setupDatePickers({pickerId:event.target.getAttribute(this.triggerDataAttributeLabel)})})})}setupOpeners(){document.addEventListener("click",function(targetDataNepaliDatePickerValue){if(targetDataNepaliDatePickerValue.target.classList.contains("ap-calendar")){const nextSibling=targetDataNepaliDatePickerValue.target.nextElementSibling,nextSiblingClasses=nextSibling.classList,parentElement=targetDataNepaliDatePickerValue.target.parentElement;parentElement.style.position="relative";targetDataNepaliDatePickerValue=targetDataNepaliDatePickerValue.target.getAttribute("data-nepali-date-picker");const apCards=document.querySelectorAll(".ap-card");apCards.forEach(function(apCard){apCard.style.display="none"}),nextSibling&&nextSiblingClasses.contains("ap-calendar-"+targetDataNepaliDatePickerValue)&&(nextSibling.style.display="block")}})}setupClosers(){document.addEventListener("click",function(e){if(!e.target.matches(".ap-calendar, .ap-card, .ap-card *")){const apCards=document.querySelectorAll(".ap-card");apCards.forEach(function(apCard){apCard.style.display="none"})}})}setupDatePickers({pickerId}){const inputField=document.querySelector(`[${this.triggerDataAttributeLabel}="${pickerId}"]`);inputField.classList.add("ap-calendar");var themeClass=this.getThemeClasses(),themeSchemeClass=this.options.darkMode?"theme-dark":"theme-light",previousButton=` + + `,nextButton=` + + `,appendData=this.getDaysHeaderList(),monthsOptionList=this.getMonthsOptionList(),yearsOptionList=this.getYearsOptionList(),appendData=` +
+
+
+ ${previousButton} +
+ + +
+ ${nextButton} +
+
+ + + + ${appendData} + + + + +
+
+ `;inputField.insertAdjacentHTML("afterend",appendData),this.initializeCalendar(inputField,this.currentMonth,this.currentYear),this.initializeDatePickerButtonsEventListeners(inputField)}initializeDatePickerButtonsEventListeners(inputField){const nextButton=inputField.nextElementSibling.querySelector(".btn-next"),previousButton=inputField.nextElementSibling.querySelector(".btn-previous");var selectedYear=inputField.nextElementSibling.querySelector(".ap-calendar-year"),selectedMonth=inputField.nextElementSibling.querySelector(".ap-calendar-month");let year=parseInt(selectedYear.value),month=parseInt(selectedMonth.value);nextButton.removeEventListener("click",()=>{}),previousButton.removeEventListener("click",()=>{}),nextButton.addEventListener("click",event=>{event.preventDefault(),year=11===month?year+1:year,month=(month+1)%12,this.initializeCalendar(inputField,month,year)}),previousButton.addEventListener("click",event=>{event.preventDefault(),year=0===month?year-1:year,month=0===month?11:month-1,this.initializeCalendar(inputField,month,year)})}initializeCalendar(inputField,month,year){const nextSibling=inputField.nextElementSibling;let calenderCard=void 0;if(nextSibling&&nextSibling.classList.contains("ap-card")&&(calenderCard=nextSibling),calenderCard&&void 0!==this.getNepaliDates()[year]){var firstDay=this.getNepaliDates()[year][1][month]-1,nepaliDatePickerDataAttribute=inputField.getAttribute(this.triggerDataAttributeLabel);calenderCard=document.querySelector(".ap-calendar-"+nepaliDatePickerDataAttribute);const tableDOM=calenderCard.querySelector(".calendar-body"),selectedYear=calenderCard.querySelector(".ap-calendar-year"),selectedMonth=calenderCard.querySelector(".ap-calendar-month");selectedYear.removeEventListener("change",()=>{}),selectedMonth.removeEventListener("change",()=>{}),selectedYear.addEventListener("change",event=>{this.initializeCalendar(inputField,month,event.target.value),this.initializeDatePickerButtonsEventListeners(inputField)}),selectedMonth.addEventListener("change",event=>{this.initializeCalendar(inputField,event.target.value,year),this.initializeDatePickerButtonsEventListeners(inputField)}),selectedYear.value=year,selectedMonth.value=month;var themeClasses=this.getThemeClasses();if(tableDOM)for(;tableDOM.firstChild;)tableDOM.removeChild(tableDOM.firstChild);let date=1;for(let i=0;i<6;i++){const row=document.createElement("tr");row.classList.add("ap-table__tbody__tr");const holidayIndices=this.options.markHolidays&&this.options.holidays.map(selectedHoliday=>this.getDaysInNepali().findIndex(dayInNepali=>dayInNepali.day.toLowerCase()===selectedHoliday.toLowerCase()));for(let j=0;j<7;j++){var nepaliDate=holidayIndices&&holidayIndices.includes(j)?"holiday-marker-color":null;if(0===i&&jthis.getDaysInMonth(month,year))break;const cell=document.createElement("td");cell.classList.add("ap-table__thead__tr_td",this.dynamicClassValues.trAndTdWidth,"ap-cell",nepaliDate);const cellButton=document.createElement("button");cellButton.classList.add("ap-cell-button",themeClasses),this.setDisabledAttributes(cellButton,year,month,date);nepaliDate="np"===this.options.locale?this.unicodeText(date):date;this.options.indicateCurrentDate&&date===parseInt(this.currentDay)&&year===parseInt(this.currentYear)&&month===parseInt(this.currentMonth)&&(cell.classList.add("active"),cellButton.classList.add("bordered-dashed")),cellButton.appendChild(document.createTextNode(nepaliDate)),cell.appendChild(cellButton),row.append(cell),date++}}tableDOM.append(row)}}}setDisabledAttributes(cellButton,year,month,date){var currentYear=this.currentYear,currentMonth=this.currentMonth+1,currentDay=this.currentDay;year=+year,month=+month,date=+date,this.options.disableBeforeToday&&(year{return``}).join("")}getDaysHeaderList(){return this.getDaysInNepali().map(day=>{return`${day[this.options.locale][this.options.daysFormat]}`}).join("")}getMonthsOptionList(){return this.getMonthsInNepali().map((month,index)=>``).join("")}closeDatePicker(){console.log("close date picker")}getMonthsInNepali(){return[{en:"Baishak",np:"बैशाख"},{en:"Jestha",np:"जेठ"},{en:"Ashad",np:"असार"},{en:"Shrawn",np:"साउन"},{en:"Bhadra",np:"भदौ"},{en:"Ashwin",np:"असोज"},{en:"Kartik",np:"कार्तिक"},{en:"Mangshir",np:"मंसिर"},{en:"Poush",np:"पुष"},{en:"Magh",np:"माघ"},{en:"Falgun",np:"फाल्गुन"},{en:"Chaitra",np:"चैत्र"}]}getLeapMonths(){return[31,29,31,30,31,30,31,31,30,31,30,31]}getNormalMonths(){return[31,28,31,30,31,30,31,31,30,31,30,31]}getNepaliDates(){return{2e3:[[30,32,31,32,31,30,30,30,29,30,29,31],[4,6,3,6,3,6,1,3,5,6,1,2]],2001:[[31,31,32,31,31,31,30,29,30,29,30,30],[5,1,4,1,4,7,3,5,6,1,2,4]],2002:[[31,31,32,32,31,30,30,29,30,29,30,30],[6,2,5,2,6,2,4,6,7,2,3,5]],2003:[[31,32,31,32,31,30,30,30,29,29,30,31],[7,3,7,3,7,3,5,7,2,3,4,6]],2004:[[30,32,31,32,31,30,30,30,29,30,29,31],[2,4,1,4,1,4,6,1,3,4,6,7]],2005:[[31,31,32,31,31,31,30,29,30,29,30,30],[3,6,2,6,2,5,1,3,4,6,7,2]],2006:[[31,31,32,32,31,30,30,29,30,29,30,30],[4,7,3,7,4,7,2,4,5,7,1,3]],2007:[[31,32,31,32,31,30,30,30,29,29,30,31],[5,1,5,1,5,1,3,5,7,1,2,4]],2008:[[31,31,31,32,31,31,29,30,30,29,29,31],[7,3,6,2,6,2,5,6,1,3,4,5]],2009:[[31,31,32,31,31,31,30,29,30,29,30,30],[1,4,7,4,7,3,6,1,2,4,5,7]],2010:[[31,31,32,32,31,30,30,29,30,29,30,30],[2,5,1,5,2,5,7,2,3,5,6,1]],2011:[[31,32,31,32,31,30,30,30,29,29,30,31],[3,6,3,6,3,6,1,3,5,6,7,2]],2012:[[31,31,31,32,31,31,29,30,30,29,30,30],[5,1,4,7,4,7,3,4,6,1,2,4]],2013:[[31,31,32,31,31,31,30,29,30,29,30,30],[6,2,5,2,5,1,4,6,7,2,3,5]],2014:[[31,31,32,32,31,30,30,29,30,29,30,30],[7,3,6,3,7,3,5,7,1,3,4,6]],2015:[[31,32,31,32,31,30,30,30,29,29,30,31],[1,4,1,4,1,4,6,1,3,4,5,7]],2016:[[31,31,31,32,31,31,29,30,30,29,30,30],[3,6,2,5,2,5,1,2,4,6,7,2]],2017:[[31,31,32,31,31,31,30,29,30,29,30,30],[4,7,3,7,3,6,2,4,5,7,1,3]],2018:[[31,32,31,32,31,30,30,29,30,29,30,30],[5,1,5,1,5,1,3,5,6,1,2,4]],2019:[[31,32,31,32,31,30,30,30,29,30,29,31],[6,2,6,2,6,2,4,6,1,2,4,5]],2020:[[31,31,31,32,31,31,30,29,30,29,30,30],[1,4,7,3,7,3,6,1,2,4,5,7]],2021:[[31,31,32,31,31,31,30,29,30,29,30,30],[2,5,1,5,1,4,7,2,3,5,6,1]],2022:[[31,32,31,32,31,30,30,30,29,29,30,30],[3,6,3,6,3,6,1,3,5,6,7,2]],2023:[[31,32,31,32,31,30,30,30,29,30,29,31],[4,7,4,7,4,7,2,4,6,7,2,3]],2024:[[31,31,31,32,31,31,30,29,30,29,30,30],[6,2,5,1,5,1,4,6,7,2,3,5]],2025:[[31,31,32,31,31,31,30,29,30,29,30,30],[7,3,6,3,6,2,5,7,1,3,4,6]],2026:[[31,32,31,32,31,30,30,30,29,29,30,31],[1,4,1,4,1,4,6,1,3,4,5,7]],2027:[[30,32,31,32,31,30,30,30,29,30,29,31],[3,5,2,5,2,5,7,2,4,5,7,1]],2028:[[31,31,32,31,31,31,30,29,30,29,30,30],[4,7,3,7,3,6,2,4,5,7,1,3]],2029:[[31,31,32,31,32,30,30,29,30,29,30,30],[5,1,4,1,4,1,3,5,6,1,2,4]],2030:[[31,32,31,32,31,30,30,30,29,29,30,31],[6,2,6,2,6,2,4,6,1,2,3,5]],2031:[[30,32,31,32,31,30,30,30,29,30,29,31],[1,3,7,3,7,3,5,7,2,3,5,6]],2032:[[31,31,32,31,31,31,30,29,30,29,30,30],[2,5,1,5,1,4,7,2,3,5,6,1]],2033:[[31,31,32,32,31,30,30,29,30,29,30,30],[3,6,2,6,3,6,1,3,4,6,7,2]],2034:[[31,32,31,32,31,30,30,30,29,29,30,31],[4,7,4,7,4,7,2,4,6,7,1,3]],2035:[[30,32,31,32,31,31,29,30,30,29,29,31],[6,1,5,1,5,1,4,5,7,2,3,4]],2036:[[31,31,32,31,31,31,30,29,30,29,30,30],[7,3,6,3,6,2,5,7,1,3,4,6]],2037:[[31,31,32,32,31,30,30,29,30,29,30,30],[1,4,7,4,1,4,6,1,2,4,5,7]],2038:[[31,32,31,32,31,30,30,30,29,29,30,31],[2,5,2,5,2,5,7,2,4,5,6,1]],2039:[[31,31,31,32,31,31,29,30,30,29,30,30],[4,7,3,6,3,6,2,3,5,7,1,3]],2040:[[31,31,32,31,31,31,30,29,30,29,30,30],[5,1,4,1,4,7,3,5,6,1,2,4]],2041:[[31,31,32,32,31,30,30,29,30,29,30,30],[6,2,5,2,6,2,4,6,7,2,3,5]],2042:[[31,32,31,32,31,30,30,30,29,29,30,31],[7,3,7,3,7,3,5,7,2,3,4,6]],2043:[[31,31,31,32,31,31,29,30,30,29,30,30],[2,5,1,4,1,4,7,1,3,5,6,1]],2044:[[31,31,32,31,31,31,30,29,30,29,30,30],[3,6,2,6,2,5,1,3,4,6,7,2]],2045:[[31,32,31,32,31,30,30,29,30,29,30,30],[4,7,4,7,4,7,2,4,5,7,1,3]],2046:[[31,32,31,32,31,30,30,30,29,29,30,31],[5,1,5,1,5,1,3,5,7,1,2,4]],2047:[[31,31,31,32,31,31,30,29,30,29,30,30],[7,3,6,2,6,2,5,7,1,3,4,6]],2048:[[31,31,32,31,31,31,30,29,30,29,30,30],[1,4,7,4,7,3,6,1,2,4,5,7]],2049:[[31,32,31,32,31,30,30,30,29,29,30,30],[2,5,2,5,2,5,7,2,4,5,6,1]],2050:[[31,32,31,32,31,30,30,30,29,30,29,31],[3,6,3,6,3,6,1,3,5,6,1,2]],2051:[[31,31,31,32,31,31,30,29,30,29,30,30],[5,1,4,7,4,7,3,5,6,1,2,4]],2052:[[31,31,32,31,31,31,30,29,30,29,30,30],[6,2,5,2,5,1,4,6,7,2,3,5]],2053:[[31,32,31,32,31,30,30,30,29,29,30,30],[7,3,7,3,7,3,5,7,2,3,4,6]],2054:[[31,32,31,32,31,30,30,30,29,30,29,31],[1,4,1,4,1,4,6,1,3,4,6,7]],2055:[[31,31,32,31,31,31,30,29,30,29,30,30],[3,6,2,6,2,5,1,3,4,6,7,2]],2056:[[31,31,32,31,32,30,30,29,30,29,30,30],[4,7,3,7,3,7,2,4,5,7,1,3]],2057:[[31,32,31,32,31,30,30,30,29,29,30,31],[5,1,5,1,5,1,3,5,7,1,2,4]],2058:[[30,32,31,32,31,30,30,30,29,30,29,31],[7,2,6,2,6,2,4,6,1,2,4,5]],2059:[[31,31,32,31,31,31,30,29,30,29,30,30],[1,4,7,4,7,3,6,1,2,4,5,7]],2060:[[31,31,32,32,31,30,30,29,30,29,30,30],[2,5,1,5,2,5,7,2,3,5,6,1]],2061:[[31,32,31,32,31,30,30,30,29,29,30,31],[3,6,3,6,3,6,1,3,5,6,7,2]],2062:[[30,32,31,32,31,31,29,30,29,30,29,31],[5,7,4,7,4,7,3,4,6,7,2,3]],2063:[[31,31,32,31,31,31,30,29,30,29,30,30],[6,2,5,2,5,1,4,6,7,2,3,5]],2064:[[31,31,32,32,31,30,30,29,30,29,30,30],[7,3,6,3,7,3,5,7,1,3,4,6]],2065:[[31,32,31,32,31,30,30,30,29,29,30,31],[1,4,1,4,1,4,6,1,3,4,5,7]],2066:[[31,31,31,32,31,31,29,30,30,29,29,31],[3,6,2,5,2,5,1,2,4,6,7,1]],2067:[[31,31,32,31,31,31,30,29,30,29,30,30],[4,7,3,7,3,6,2,4,5,7,1,3]],2068:[[31,31,32,32,31,30,30,29,30,29,30,30],[5,1,4,1,5,1,3,5,6,1,2,4]],2069:[[31,32,31,32,31,30,30,30,29,29,30,31],[6,2,6,2,6,2,4,6,1,2,3,5]],2070:[[31,31,31,32,31,31,29,30,30,29,30,30],[1,4,7,3,7,3,6,7,2,4,5,7]],2071:[[31,31,32,31,31,31,30,29,30,29,30,30],[2,5,1,5,1,4,7,2,3,5,6,1]],2072:[[31,32,31,32,31,30,30,29,30,29,30,30],[3,6,3,6,3,6,1,3,4,6,7,2]],2073:[[31,32,31,32,31,30,30,30,29,29,30,31],[4,7,4,7,4,7,2,4,6,7,1,3]],2074:[[31,31,31,32,31,31,30,29,30,29,30,30],[6,2,5,1,5,1,4,6,7,2,3,5]],2075:[[31,31,32,31,31,31,30,29,30,29,30,30],[7,3,6,3,6,2,5,7,1,3,4,6]],2076:[[31,32,31,32,31,30,30,30,29,29,30,30],[1,4,1,4,1,4,6,1,3,4,5,7]],2077:[[31,32,31,32,31,30,30,30,29,30,29,31],[2,5,2,5,2,5,7,2,4,5,7,1]],2078:[[31,31,31,32,31,31,30,29,30,29,30,30],[4,7,3,6,3,6,2,4,5,7,1,3]],2079:[[31,31,32,31,31,31,30,29,30,29,30,30],[5,1,4,1,4,7,3,5,6,1,2,4]],2080:[[31,32,31,32,31,30,30,30,29,29,30,30],[6,2,6,2,6,2,4,6,1,2,3,5]],2081:[[31,31,32,32,31,30,30,30,29,30,30,30],[7,3,6,3,7,3,5,7,2,3,5,7]],2082:[[30,32,31,32,31,30,30,30,29,30,30,30],[2,4,1,4,1,4,6,1,3,4,6,1]],2083:[[31,31,32,31,31,30,30,30,29,30,30,30],[3,6,2,6,2,5,7,2,4,5,7,2]],2084:[[31,31,32,31,31,30,30,30,29,30,30,30],[4,7,3,7,3,6,1,3,5,6,1,3]],2085:[[31,32,31,32,30,31,30,30,29,30,30,30],[5,1,5,1,5,7,3,5,7,1,3,5]],2086:[[30,32,31,32,31,30,30,30,29,30,30,30],[7,2,6,2,6,2,4,6,1,2,4,6]],2087:[[31,31,32,31,31,31,30,30,29,30,30,30],[1,4,7,4,7,3,6,1,3,4,6,1]],2088:[[30,31,32,32,30,31,30,30,29,30,30,30],[3,5,1,5,2,4,7,2,4,5,7,2]],2089:[[30,32,31,32,31,30,30,30,29,30,30,30],[4,6,3,6,3,6,1,3,5,6,1,3]],2090:[[30,32,31,32,31,30,30,30,29,30,30,30],[5,7,4,7,4,7,2,4,6,7,2,4]]}}getDaysInNepali(){return[{day:"Sunday",en:{ddd:"Sunday",dd:"Sun",d:"S"},np:{ddd:"आइतबार",dd:"आइत",d:"आ"}},{day:"Monday",en:{ddd:"Monday",dd:"Mon",d:"M"},np:{ddd:"सोमबार",dd:"सोम",d:"सो"}},{day:"Tuesday",en:{ddd:"Tuesday",dd:"Tue",d:"T"},np:{ddd:"मंगलबार",dd:"मंगल",d:"मं"}},{day:"Wednesday",en:{ddd:"Wednesday",dd:"Wed",d:"W"},np:{ddd:"बुधबार",dd:"बुध",d:"बु"}},{day:"Thursday",en:{ddd:"Thursday",dd:"Thu",d:"T"},np:{ddd:"बिहिबार",dd:"बिहि",d:"बि"}},{day:"Friday",en:{ddd:"Friday",dd:"Fri",d:"F"},np:{ddd:"शुक्रबार",dd:"शुक्र",d:"शु"}},{day:"Saturday",en:{ddd:"Saturday",dd:"Sat",d:"S"},np:{ddd:"शनिबार",dd:"शनि",d:"श"}}]}getDaysInMonth(month,year){return this.getNepaliDates()[year][0][month]}unicodeText(text){const chars={0:"०",1:"१",2:"२",3:"३",4:"४",5:"५",6:"६",7:"७",8:"८",9:"९"};return text.toString().replace(/[0123456789]/g,m=>chars[m])}decodeUnicodeToEnglishText(text){const chars={"०":"0","१":"1","२":"2","३":"3","४":"4","५":"5","६":"6","७":"7","८":"8","९":"9"};return text.toString().replace(/[०१२३४५६७८९]/g,m=>chars[m])}getPositionClasses(){switch(this.options.position){case"left":default:return"ap-position-left";case"right":return"ap-position-right";case"center":return"ap-position-center"}}convertToNepaliDate(nepaliDate,nepaliYear,nepaliMonth){var nepaliDate=this.calculateTotalEnglishDays(nepaliDate=+nepaliDate,nepaliYear=+nepaliYear,nepaliMonth=+nepaliMonth),{nepaliYear,nepaliMonth,nepaliDate}=this.performCalculationBasedOnEnglishDays(nepaliDate);return{year:nepaliYear,month:nepaliMonth-1,date:nepaliDate}}calculateTotalEnglishDays(year,month,day){let totalEnglishDays=0;for(let i=0;ilastDayOfMonth&&(nepaliMonth++,nepaliDay=1,j++),7 + + + + + + + + + +``` + +#### Config Options +```javascript +let config = { + format: 'YYYY-MM-DD', // 'YYYY-MM-DD', 'YYYY/MM/DD', 'YYYY.MM.DD', 'DD-MM-YYYY', 'DD/MM/YYYY', 'DD.MM.YYYY' + disableAfterToday: false, // boolean: true | false + disableBeforeToday: false, // boolean: true | false + disableToday: false, // boolean: true | false + closeOnDateSelect: true, // boolean: true | false + markHolidays: true, // boolean: true | false + holidays: ['Saturday'], // ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] + indicateCurrentDate: true, // boolean: true | false + setCurrentDate: false, // boolean: true | false + position: 'left', // 'left', 'right' or 'center' + daysFormat: 'dd', // 'ddd' for full day name, 'dd' for short day name, 'd' for 1 letter day name + locale: 'np', // 'np' for nepali, 'en' for english + theme: 'flat', // bordered | soft | flat + darkMode: false, // boolean: true | false +} +```` + +#### English Date to Nepali Date Conversion + +```javascript +// To Convert English Date to Nepali Date + +let NepaliDatePicker = new NepaliDatePicker(); + +NepaliDatePicker.convertToNepaliDate(2053, 1, 10) + +// Result: {year: 2053, month: 1, day: 10} +``` + +#### Features + +- [x] ~~Proper UI for Date Picker~~ +- [x] ~~Convert English Date to Nepali Date~~ +- [ ] Convert Nepali Date to English Date +- [x] ~~Add Date Picker to Multiple Input Fields~~ +- [x] ~~Remove jQuery Dependency~~ +- [ ] Support Time Select +- [ ] Calculate Age on Date +- [ ] Add Configurations to Date Picker + - [x] ~~Close/Hide Date Picker on Date Select~~ + - [ ] Disable features on + - [ ] Today's Date + - [ ] Before Today's Date + - [ ] Specific Dates + - [ ] Specific Days + - [ ] Specific Months + - [ ] Specific Years + - [ ] Mark Holidays on + - [x] ~~Specific Days~~ + - [ ] Specific Dates + - [ ] Date Ranges + - [x] ~~Set Current Date Indicator~~ + - [x] ~~Set Current Date on Input Value~~ + - [x] ~~Set Date Format~~ + - [x] ~~YYYY-MM-DD~~ + - [x] ~~YYYY/MM/DD~~ + - [x] ~~YYYY.MM.DD~~ + - [x] ~~DD-MM-YYYY~~ + - [x] ~~DD/MM/YYYY~~ + - [x] ~~DD.MM.YYYY~~ + - [x] ~~Picker Position~~ + - [x] ~~Left~~ + - [x] ~~Center~~ + - [x] ~~Right~~ + - [x] ~~Date Picker Days Format~~ + - [x] ~~Full Name (ddd) [Eg. Sunday, आइतबार]~~ + - [x] ~~Short Name (dd) [Eg. Sun, आइत]~~ + - [x] ~~Very Short Name (d) [Eg. S, आ]~~ + - [x] ~~Language Support (np/en)~~ + - [x] ~~English~~ + - [x] ~~Nepali~~ + - [ ] Date Picker Theme + - [x] ~~Light~~ + - [x] ~~Dark~~ + - [ ] Min Date + - [ ] Max Date \ No newline at end of file