ponjika
Version:
Bengali ponjika based on gregorian date
2 lines (1 loc) • 3.72 kB
JavaScript
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).ponjika={})}(this,(function(n){"use strict";function t(n,t){void 0===t&&(t=!1);var e={1:"১",2:"২",3:"৩",4:"৪",5:"৫",6:"৬",7:"৭",8:"৮",9:"৯",0:"০"},a=n.toString().split("");a.forEach((function(n,t){a[t]=e[n]}));var o=a.join("");return t&&1===o.length?e[0]+o:o}var e=function(n,e){void 0===n&&(n=new Date),void 0===e&&(e=!0);var a=this;this._bengliMonths={Poush:"পৌষ",Maagh:"মাঘ",Falgun:"ফাল্গুন",Chaitra:"চৈত্র",Boisakh:"বৈশাখ",Joistho:"জ্যৈষ্ঠ",Ashar:"আষাঢ়",Shraban:"শ্রাবণ",Vadro:"ভাদ্র",Ashin:"আশ্বিন",Kartik:"কার্তিক",Agrahan:"অগ্রহায়ণ"},this._bengaliWeekDays={Robibar:"রবিবার",Sombar:"সোমবার",Mongolbar:"মঙ্গলবার",Budhbar:"বুধবার",Brihospotibar:"বৃহস্পতিবার",Shukrobar:"শুক্রবার",Shonibar:"শনিবার"},this._bengliSeasons={Sheet:"শীত",Bosonto:"বসন্ত",Grismo:"গ্রীষ্ম",Borsha:"বর্ষা",Sorot:"শরৎ",Hemonto:"হেমন্ত"},this._bengliMonthNo=[9,10,11,12,1,2,3,4,5,6,7,8],this._totalDaysInMonth=[30,30,29,30,31,31,31,31,31,31,30,30],this._midMonthDate=[14,13,14,13,14,14,15,15,15,16,15,15],this._lastMonthIndex=3,this._leapYearMonthIndex=2,this._date=0,this._month=0,this._year=0,this._bnYear="",this._bnMonth="",this._bnMonthNo="",this._bnDate="",this._bnDay="",this._season="",this._isLeapYear=function(n){return n%4==0&&n%100!=0||n%400==0},this._toBDTimezone=function(n){var t=n.toLocaleString("en",{timeZone:"Asia/Dhaka"});return new Date(t)},this._getDateMonthYear=function(n){void 0===n&&(n=a._refDate);var t=n.getFullYear(),e=n.getMonth();return{date:n.getDate(),month:e,year:t}},this._gregorianToBengaliYear=function(n,t,e){var o=n-594;return(t>a._lastMonthIndex||t===a._lastMonthIndex&&e>13)&&(o+=1),o},this._getBengaliDate=function(n){void 0===n&&(n=a._refDate);var e=a._toBDTimezone(n),o=a._getDateMonthYear(e),i=o.date,h=o.month,r=o.year,s=a._gregorianToBengaliYear(r,h,i),_=a._totalDaysInMonth[h],b=0,g="",l=0;i<=a._midMonthDate[h]?(h===a._leapYearMonthIndex&&a._isLeapYear(r)&&(_=a._totalDaysInMonth[h]+1),b=_+i-a._midMonthDate[h],l=h,g=Object.keys(a._bengliMonths)[l]):(b=i-a._midMonthDate[h],l=(h+1)%12,g=Object.keys(a._bengliMonths)[l]);var D=Object.keys(a._bengliSeasons)[Math.floor(l/2)];a._year=s,a._date=b,a._month=a._bengliMonthNo[l],a._bnYear=t(s,a._bnPrefixZero),a._bnMonth=g,a._bnMonthNo=t(a._bengliMonthNo[l],a._bnPrefixZero),a._bnDate=t(b,a._bnPrefixZero),a._bnDay=Object.keys(a._bengaliWeekDays)[e.getDay()],a._season=D},this.getBengaliDate=function(){return"".concat(a._bengaliWeekDays[a._bnDay],", ").concat(a._bnDate," ").concat(a._bengliMonths[a._bnMonth]," ").concat(a._bnYear)},this.getBengaliPhoneticDate=function(){return"".concat(a._bnDay,", ").concat(a._date," ").concat(a._bnMonth," ").concat(a._year)},this.getDateBengaliNumeral=function(){return{bnDate:a._bnDate,bnMonth:a._bnMonthNo,bnYear:a._bnYear}},this.getDateNumeral=function(){return{year:a._year,month:a._month,date:a._date}},this.getDetails=function(){return{year:a._year,month:a._month,date:a._date,bnYear:a._bnYear,bnMonthNo:a._bnMonthNo,bnDate:a._bnDate,bnMonth:a._bengliMonths[a._bnMonth],bnDay:a._bengaliWeekDays[a._bnDay],season:a._bengliSeasons[a._season],bnMonthPhn:a._bnMonth,bnDayPhn:a._bnDay,seasonPhn:a._season}},this._refDate=n,this._bnPrefixZero=e,this._getBengaliDate()};n.Ponjika=e,n.enToBnNumber=t}));