bn-calendar 1.2.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1 +1,1115 @@
1
- import{a as e,c as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./convert-Byg6yAIU.mjs";function c(e){let t=a(e);return t?t%4==0&&t%100!=0||t%400==0:!1}const l=864e5,u=Object.freeze({"revised-2019":{normal:[31,31,31,31,31,31,30,30,30,30,29,30],leap:[31,31,31,31,31,31,30,30,30,30,30,30]},"revised-1966":{normal:[31,31,31,31,31,30,30,30,30,30,30,30],leap:[31,31,31,31,31,30,30,30,30,30,31,30]}}),d=Object.freeze([{bn:`গ্রীষ্ম`,en:`Grisma (Summer)`},{bn:`বর্ষা`,en:`Barsa (Monsoon)`},{bn:`শরৎ`,en:`Sarat (Autumn)`},{bn:`হেমন্ত`,en:`Hemanta (Late-Autumn)`},{bn:`শীত`,en:`Shhit (Winter)`},{bn:`বসন্ত`,en:`Basanta (Spring)`}]),f=Object.freeze([{bn:`রবিবার`,en:`Robibar (Sunday)`,short:`র`},{bn:`সোমবার`,en:`Shombar (Monday)`,short:`সো`},{bn:`মঙ্গলবার`,en:`Mongolbar (Tuesday)`,short:`ম`},{bn:`বুধবার`,en:`Budhbar (Wednesday)`,short:`বু`},{bn:`বৃহস্পতিবার`,en:`Brihoshpotibar (Thursday)`,short:`বৃ`},{bn:`শুক্রবার`,en:`Shukrobar (Friday)`,short:`শু`},{bn:`শনিবার`,en:`Shonibar (Saturday)`,short:`শ`}]),p=Object.freeze([{bn:`বৈশাখ`,en:`Boishakh`,short:`বৈ`},{bn:`জ্যৈষ্ঠ`,en:`Joishtho`,short:`জ্য`},{bn:`আষাঢ়`,en:`Asharh`,short:`আ`},{bn:`শ্রাবণ`,en:`Srabon`,short:`শ্রা`},{bn:`ভাদ্র`,en:`Bhadro`,short:`ভা`},{bn:`আশ্বিন`,en:`Ashwin`,short:`আ`},{bn:`কার্তিক`,en:`Kartik`,short:`কা`},{bn:`অগ্রহায়ণ`,en:`Ogrohayon`,short:`অ`},{bn:`পৌষ`,en:`Poush`,short:`পৌ`},{bn:`মাঘ`,en:`Magh`,short:`মা`},{bn:`ফাল্গুন`,en:`Falgun`,short:`ফা`},{bn:`চৈত্র`,en:`Choitro`,short:`চৈ`}]),m=Object.freeze([`YYYY`,`YY`,`yyyy`,`yy`]),h=Object.freeze([`M`,`MM`,`mmm`,`mmmm`]),g=Object.freeze([`DD`,`D`,`Do`]),_=Object.freeze([`d`,`dd`,`ddd`]),v=Object.freeze([`H`,`HH`,`hh`,`h`]),y=Object.freeze([`mm`,`m`]),b=Object.freeze([`ss`,`s`]),x=Object.freeze([`ms`,`mss`]),S=Object.freeze([`a`,`A`]),C=Object.freeze([`Z`,`ZZ`,`S`,`SS`]),w=Object.freeze([...m,...h,..._,...g,...v,...y,...b,...x,...S,...C].sort((e,t)=>t.length-e.length));function T(e,t){let n=RegExp(`^(${w.join(`|`)})`),r=``,i=0;for(;i<e.length;){if(e[i]===`[`){let t=e.indexOf(`]`,i);if(t!==-1){r+=e.slice(i+1,t),i=t+1;continue}}let a=n.exec(e.slice(i));a?(r+=t[a[0]]??a[0],i+=a[0].length):(r+=e[i],i++)}return r}function E(e,t,n){return n===`revised-1966`?e%4==2:c(t)}function D(e,t){let n=d[Math.floor(e/2)];return t===`en`?n.en:n.bn}function O(e){let t=e.getMonth();return{gy:e.getFullYear(),$gm:t,gm:t+1,gd:e.getDate(),wd:e.getDay()}}function k(e){let{gy:t,gm:n,gd:r}=O(e);return n<4||n===4&&r<14?t-1:t}function A(e){return k(e)-593}function j(e){let{gy:t,$gm:n,gd:r}=O(e);return Date.UTC(t,n,r)}function M(e){return Math.floor((j(e)-Date.UTC(k(e),3,14))/l)}function N(e,t){let n=t??`revised-2019`,r=E(A(e),e.getFullYear(),n)?u?.[n].leap:u?.[n].normal,i=M(e),a=0;for(;i>=r[a];)i-=r[a],a++;return{days:i,monthIdx:a}}function P(e,t=2){return e.padStart(t,`০`)}var F=class a{variant;year;month;date;gregorian;weekDay;isoWeekDay;constructor(e,i,o,c){this.variant=this.#r(e,i,o,c);let l=e instanceof Date?e:new Date(n(e)&&!a.isBanglaDateString(e)||t(e)&&!a.isBanglaYearEn(e)?e:Date.now());isNaN(l.getTime())&&(l=new Date);let{year:u,month:d,monthDate:f}=this.#i(l),p=a.isBanglaYear(e)?s(e):t(e)&&a.isBanglaYearEn(e)?e:u,m=a.isBanglaMonth(i)?s(i):a.isBanglaMonthEn(i)?i:d,h=a.isBanglaDate(o)?s(o):a.isBanglaDateEn(o)?o:f;if(a.isBanglaDateString(e)){let t=e.replace(/['"]/g,``).split(`-`);p=s(t[0]),m=s(t[1]),h=s(t[2])}let{gregYear:g}=this.#e(p,m),{bnMonthTable:_}=this.#t(g,p),v=_[m-1];h>v&&(h-=v,m===12?(m=1,p+=1):m+=1),this.year={bn:r(p),en:p},this.month={bn:r(m),en:m},this.date={bn:r(h),en:h};let{gy:y,gm:b,gd:x,wd:S}=O(this.toDate());this.gregorian={year:y,month:b,date:x},this.weekDay=S,this.isoWeekDay=S===0?7:S}[Symbol.toPrimitive](e){return e===`number`?this.valueOf():this.toJSON()}get[Symbol.toStringTag](){return this.toJSON()}valueOf(){return this.toDate().getTime()}toJSON(){let{year:e,month:t,date:n}=this;return`${P(e.bn,4)}-${P(t.bn)}-${P(n.bn)}`}isLeapYear(){let{gregYear:e}=this.#e();return this.#t(e).isBnLeapYear}toDate(){let{baseGregYear:e,gregYear:t}=this.#e(),{bnMonthTable:n}=this.#t(t),r=Date.UTC(e,3,13),i=this.date.en;for(let e=0;e<this.month.en-1;e++)i+=n[e];return new Date(i*l+r)}getSeasonName(e){return D(this.month.en-1,e)}getMonthName(e){let t=p[this.month.en-1];return e===`en`?t.en:t.bn}getDayName(e){let t=f[this.weekDay];return e===`en`?t.en:t.bn}addDays(e){let t=this.toDate();return new a(t.setDate(t.getDate()+e),{variant:this.variant})}addWeeks(e){let t=this.toDate();return new a(t.setDate(t.getDate()+e*7),{variant:this.variant})}addMonths(e,t=!0){if(t){let t=this.toDate();return new a(t.setMonth(t.getMonth()+e),{variant:this.variant})}else{let{variant:t,year:n,month:r,date:i}=this,a=r.en+e,o=n.en;for(;a>12;)a-=12,o+=1;for(;a<1;)a+=12,--o;return this.#n(o,a,i.en,t)}}addYears(e,t=!0){let{variant:n,year:r,month:i,date:o}=this,s=r.en+e;return t?new a(s,i.en,o.en,{variant:n}):this.#n(s,i.en,o.en,n)}startOfMonth(){let{year:e,month:t,variant:n}=this;return new a(e.en,t.en,1,{variant:n})}endOfMonth(){let{year:e,month:t,variant:n}=this;return new a(e.en,t.en,this.daysInMonth(),{variant:n})}startOfYear(){let{year:e,variant:t}=this;return new a(e.en,1,1,{variant:t})}endOfYear(){let{year:e,variant:t}=this;return new a(e.en,12,30,{variant:t})}daysInMonth(e){let{gregYear:t}=this.#e(),{bnMonthTable:n}=this.#t(t);return n[(e??this.month.en)-1]}toString(){return this.#a(`bn`)}toStringEn(){return this.#a(`en`)}format(e){let{year:t,month:n,date:r,weekDay:i}=this,a=this.getSeasonName(),o=p[n.en-1],s=f[i],c=P(t.bn,4),l={YYYY:c,YY:c.slice(-2),yyyy:c,yy:c.slice(-2),M:n.bn,MM:P(n.bn),mmm:o.short,mmmm:o.bn,d:s.short,dd:s.bn.replace(`বার`,``),ddd:s.bn,D:r.bn,DD:P(r.bn),Do:r.bn,S:a,SS:a+`কাল`};return T(e||`ddd, DD mmmm (SS), YYYY বঙ্গাব্দ`,l)}#e(e,t){let n=(e??this.year.en)+593;return{baseGregYear:n,gregYear:(t??this.month.en)>10?n+1:n}}#t(e,t){let n=E(t??this.year.en,e,this.variant);return{bnMonthTable:n?u?.[this.variant].leap:u?.[this.variant].normal,isBnLeapYear:n}}#n(e,t,n,r){let{gregYear:i}=this.#e(e,t),{bnMonthTable:o}=this.#t(i,e);return new a(e,t,Math.min(n,o[t-1]),{variant:r})}#r(e,t,n,r){return this.$hasVariantConfig(e)?e.variant:this.$hasVariantConfig(t)?t.variant:this.$hasVariantConfig(n)?n.variant:this.$hasVariantConfig(r)?r.variant:`revised-2019`}#i(e){let t=A(e),{days:n,monthIdx:r}=N(e,this.variant);return{year:t,month:r+1,monthDate:n+1}}#a(e=`bn`){let{year:t,date:n}=this;return`${this.getDayName(e)}, ${n[e]} ${this.getMonthName(e)}, ${t[e]} [${this.getSeasonName(e)}]`}$hasVariantConfig(t){return e(t,[`variant`])&&o(t.variant)&&(t.variant===`revised-1966`||t.variant===`revised-2019`)}static isBanglaYear(e){return o(e)&&/^(?:০{0,3}[১-৯][০-৯]{0,3}|০)$/.test(e.trim())}static isBanglaYearEn(e){return i(e)&&e>=0&&e<=9999}static isBanglaMonth(e){return o(e)&&/^(?:০?[১-৯]|১০|১১|১২)$/.test(e.trim())}static isBanglaMonthEn(e){return i(e)&&e>=1&&e<=12}static isBanglaDate(e){return o(e)&&/^(?:০?[১-৯]|[১২][০-৯]|৩০|৩১)$/.test(e.trim())}static isBanglaDateEn(e){return i(e)&&e>=1&&e<=31}static isBanglaDateString(e){if(o(e)&&e.includes(`-`)){let[t,n,r]=e.replace(/['"]/g,``).split(`-`);return a.isBanglaYear(t)&&a.isBanglaMonth(n)&&a.isBanglaDate(r)}return!1}};export{F as BanglaCalendar,F as BnCalendar,F as Bongabdo};
1
+ /**
2
+ * Copyright 2026 - present Nazmul Hassan
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { a as isObjectWithKeys, c as isNumber, i as isDateString, n as digitToBangla, o as isInteger, r as normalizeNumber, s as isNonEmptyString, t as banglaToDigit } from "./convert-B3CETM-p.mjs";
18
+
19
+ //#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/date/guards.js
20
+ function isLeapYear(year) {
21
+ const $year = normalizeNumber(year);
22
+ return $year ? $year % 4 === 0 && $year % 100 !== 0 || $year % 400 === 0 : false;
23
+ }
24
+
25
+ //#endregion
26
+ //#region src/constants.ts
27
+ /** Milliseconds per day */
28
+ const MS_PER_DAY = 864e5;
29
+ /** Bangla month days table for different variants */
30
+ const BN_MONTH_TABLES = /* @__PURE__ */ Object.freeze({
31
+ "revised-2019": {
32
+ normal: [
33
+ 31,
34
+ 31,
35
+ 31,
36
+ 31,
37
+ 31,
38
+ 31,
39
+ 30,
40
+ 30,
41
+ 30,
42
+ 30,
43
+ 29,
44
+ 30
45
+ ],
46
+ leap: [
47
+ 31,
48
+ 31,
49
+ 31,
50
+ 31,
51
+ 31,
52
+ 31,
53
+ 30,
54
+ 30,
55
+ 30,
56
+ 30,
57
+ 30,
58
+ 30
59
+ ]
60
+ },
61
+ "revised-1966": {
62
+ normal: [
63
+ 31,
64
+ 31,
65
+ 31,
66
+ 31,
67
+ 31,
68
+ 30,
69
+ 30,
70
+ 30,
71
+ 30,
72
+ 30,
73
+ 30,
74
+ 30
75
+ ],
76
+ leap: [
77
+ 31,
78
+ 31,
79
+ 31,
80
+ 31,
81
+ 31,
82
+ 30,
83
+ 30,
84
+ 30,
85
+ 30,
86
+ 30,
87
+ 31,
88
+ 30
89
+ ]
90
+ }
91
+ });
92
+ /** List of Bangla season names in Bangla and English */
93
+ const BN_SEASONS = /* @__PURE__ */ Object.freeze([
94
+ {
95
+ bn: "গ্রীষ্ম",
96
+ en: "Grisma (Summer)"
97
+ },
98
+ {
99
+ bn: "বর্ষা",
100
+ en: "Barsa (Monsoon)"
101
+ },
102
+ {
103
+ bn: "শরৎ",
104
+ en: "Sarat (Autumn)"
105
+ },
106
+ {
107
+ bn: "হেমন্ত",
108
+ en: "Hemanta (Late-Autumn)"
109
+ },
110
+ {
111
+ bn: "শীত",
112
+ en: "Shhit (Winter)"
113
+ },
114
+ {
115
+ bn: "বসন্ত",
116
+ en: "Basanta (Spring)"
117
+ }
118
+ ]);
119
+ /** List of Bangla day names in Bangla and English */
120
+ const BN_DAYS = /* @__PURE__ */ Object.freeze([
121
+ {
122
+ bn: "রবিবার",
123
+ en: "Robibar (Sunday)",
124
+ short: "র"
125
+ },
126
+ {
127
+ bn: "সোমবার",
128
+ en: "Shombar (Monday)",
129
+ short: "সো"
130
+ },
131
+ {
132
+ bn: "মঙ্গলবার",
133
+ en: "Mongolbar (Tuesday)",
134
+ short: "ম"
135
+ },
136
+ {
137
+ bn: "বুধবার",
138
+ en: "Budhbar (Wednesday)",
139
+ short: "বু"
140
+ },
141
+ {
142
+ bn: "বৃহস্পতিবার",
143
+ en: "Brihoshpotibar (Thursday)",
144
+ short: "বৃ"
145
+ },
146
+ {
147
+ bn: "শুক্রবার",
148
+ en: "Shukrobar (Friday)",
149
+ short: "শু"
150
+ },
151
+ {
152
+ bn: "শনিবার",
153
+ en: "Shonibar (Saturday)",
154
+ short: "শ"
155
+ }
156
+ ]);
157
+ /** List of Bangla month names in Bangla and English */
158
+ const BN_MONTHS = /* @__PURE__ */ Object.freeze([
159
+ {
160
+ bn: "বৈশাখ",
161
+ en: "Boishakh",
162
+ short: "বৈ"
163
+ },
164
+ {
165
+ bn: "জ্যৈষ্ঠ",
166
+ en: "Joishtho",
167
+ short: "জ্য"
168
+ },
169
+ {
170
+ bn: "আষাঢ়",
171
+ en: "Asharh",
172
+ short: "আ"
173
+ },
174
+ {
175
+ bn: "শ্রাবণ",
176
+ en: "Srabon",
177
+ short: "শ্রা"
178
+ },
179
+ {
180
+ bn: "ভাদ্র",
181
+ en: "Bhadro",
182
+ short: "ভা"
183
+ },
184
+ {
185
+ bn: "আশ্বিন",
186
+ en: "Ashwin",
187
+ short: "আ"
188
+ },
189
+ {
190
+ bn: "কার্তিক",
191
+ en: "Kartik",
192
+ short: "কা"
193
+ },
194
+ {
195
+ bn: "অগ্রহায়ণ",
196
+ en: "Ogrohayon",
197
+ short: "অ"
198
+ },
199
+ {
200
+ bn: "পৌষ",
201
+ en: "Poush",
202
+ short: "পৌ"
203
+ },
204
+ {
205
+ bn: "মাঘ",
206
+ en: "Magh",
207
+ short: "মা"
208
+ },
209
+ {
210
+ bn: "ফাল্গুন",
211
+ en: "Falgun",
212
+ short: "ফা"
213
+ },
214
+ {
215
+ bn: "চৈত্র",
216
+ en: "Choitro",
217
+ short: "চৈ"
218
+ }
219
+ ]);
220
+ const YEAR_FORMATS = /* @__PURE__ */ Object.freeze([
221
+ "YYYY",
222
+ "YY",
223
+ "yyyy",
224
+ "yy"
225
+ ]);
226
+ const MONTH_FORMATS = /* @__PURE__ */ Object.freeze([
227
+ "M",
228
+ "MM",
229
+ "mmm",
230
+ "mmmm"
231
+ ]);
232
+ const DATE_FORMATS = /* @__PURE__ */ Object.freeze([
233
+ "DD",
234
+ "D",
235
+ "Do"
236
+ ]);
237
+ const DAY_FORMATS = /* @__PURE__ */ Object.freeze([
238
+ "d",
239
+ "dd",
240
+ "ddd"
241
+ ]);
242
+ const HOUR_FORMATS = /* @__PURE__ */ Object.freeze([
243
+ "H",
244
+ "HH",
245
+ "hh",
246
+ "h"
247
+ ]);
248
+ const MINUTE_FORMATS = /* @__PURE__ */ Object.freeze(["mm", "m"]);
249
+ const SECOND_FORMATS = /* @__PURE__ */ Object.freeze(["ss", "s"]);
250
+ const MILLISECOND_FORMATS = /* @__PURE__ */ Object.freeze(["ms", "mss"]);
251
+ const TIME_FORMATS = /* @__PURE__ */ Object.freeze(["a", "A"]);
252
+ const EXTRA_FORMATS = /* @__PURE__ */ Object.freeze([
253
+ "Z",
254
+ "ZZ",
255
+ "S",
256
+ "SS"
257
+ ]);
258
+ const SORTED_TIME_FORMATS = /* @__PURE__ */ Object.freeze([
259
+ ...YEAR_FORMATS,
260
+ ...MONTH_FORMATS,
261
+ ...DAY_FORMATS,
262
+ ...DATE_FORMATS,
263
+ ...HOUR_FORMATS,
264
+ ...MINUTE_FORMATS,
265
+ ...SECOND_FORMATS,
266
+ ...MILLISECOND_FORMATS,
267
+ ...TIME_FORMATS,
268
+ ...EXTRA_FORMATS
269
+ ].sort((a, b) => b.length - a.length));
270
+
271
+ //#endregion
272
+ //#region src/helpers.ts
273
+ /** Core formatting logic shared by `formatDate` and `Chronos`, `BanglaCalendar` classes */
274
+ function _formatDateCore(format, dateComponents) {
275
+ const tokenRegex = new RegExp(`^(${SORTED_TIME_FORMATS.join("|")})`);
276
+ let result = "";
277
+ let i = 0;
278
+ while (i < format.length) {
279
+ if (format[i] === "[") {
280
+ const end = format.indexOf("]", i);
281
+ if (end !== -1) {
282
+ result += format.slice(i + 1, end);
283
+ i = end + 1;
284
+ continue;
285
+ }
286
+ }
287
+ const match = tokenRegex.exec(format.slice(i));
288
+ if (match) {
289
+ result += dateComponents[match[0]] ?? match[0];
290
+ i += match[0].length;
291
+ } else {
292
+ result += format[i];
293
+ i++;
294
+ }
295
+ }
296
+ return result;
297
+ }
298
+ /** Check whether a Bangla year is leap by Gregorian and Bangla years and calendar variant */
299
+ function _isBnLeapYear(by, gy, v) {
300
+ return v === "revised-1966" ? by % 4 === 2 : isLeapYear(gy);
301
+ }
302
+ /** Get Bangla season name by month index (`0-11`) */
303
+ function _getBnSeason(month, locale) {
304
+ const season = BN_SEASONS[Math.floor(month / 2)];
305
+ return locale === "en" ? season.en : season.bn;
306
+ }
307
+ /** Extract selective unit values from {@link Date} object */
308
+ function _extractDateUnits(date) {
309
+ const month = date.getMonth();
310
+ return {
311
+ gy: date.getFullYear(),
312
+ $gm: month,
313
+ gm: month + 1,
314
+ gd: date.getDate(),
315
+ wd: date.getDay()
316
+ };
317
+ }
318
+ /** Get Gregorian base year from {@link Date} object for Bangla year */
319
+ function _getGregBaseYear(date) {
320
+ const { gy, gm, gd } = _extractDateUnits(date);
321
+ return gm < 4 || gm === 4 && gd < 14 ? gy - 1 : gy;
322
+ }
323
+ /** Get Bangla year from {@link Date} object */
324
+ function _getBnYear(date) {
325
+ return _getGregBaseYear(date) - 593;
326
+ }
327
+ /** Get timestamp in milliseconds between midnight, January 1, 1970 (UTC) and the specified {@link Date} object */
328
+ function _getUtcTs(date) {
329
+ const { gy, $gm, gd } = _extractDateUnits(date);
330
+ return Date.UTC(gy, $gm, gd);
331
+ }
332
+ /** Get number of days elapsed since midnight April 14, 1970 (UTC) for specific {@link Date} */
333
+ function _getElapsedDays(date) {
334
+ return Math.floor((_getUtcTs(date) - Date.UTC(_getGregBaseYear(date), 3, 14)) / MS_PER_DAY);
335
+ }
336
+ /** Get number of days elapsed since midnight April 14, 1970 (UTC) and month index for specific `Date` and Bangla calendar variant */
337
+ function _bnDaysMonthIdx(date, variant) {
338
+ const v = variant ?? "revised-2019";
339
+ const table = _isBnLeapYear(_getBnYear(date), date.getFullYear(), v) ? BN_MONTH_TABLES?.[v].leap : BN_MONTH_TABLES?.[v].normal;
340
+ let days = _getElapsedDays(date);
341
+ let monthIdx = 0;
342
+ while (days >= table[monthIdx]) {
343
+ days -= table[monthIdx];
344
+ monthIdx++;
345
+ }
346
+ return {
347
+ days,
348
+ monthIdx
349
+ };
350
+ }
351
+ /**
352
+ * Pad at the start of a string with Bangla zero (`'০'`)
353
+ * @param str String to pad with
354
+ * @param length Maximum length to pad, default is `2`
355
+ * @returns The padded string
356
+ */
357
+ function _padShunno(str, length = 2) {
358
+ return str.padStart(length, "০");
359
+ }
360
+
361
+ //#endregion
362
+ //#region src/BanglaCalendar.ts
363
+ /**
364
+ * @class Represents a date in the Bangla calendar system with support for different variants.
365
+ * - This class provides functionality to create, manipulate, convert dates between the Bangla and Gregorian calendar systems.
366
+ * - It supports two Bangla calendar variants: `'revised-2019'` (default) and `'revised-1966'`.
367
+ *
368
+ * @example
369
+ * // Create from current date
370
+ * const today = new BanglaCalendar();
371
+ *
372
+ * // Create from Bangla date string (Bangla digit)
373
+ * const date0 = new BanglaCalendar('১৪৩২-১১-০৮');
374
+ *
375
+ * // Create from Gregorian date
376
+ * const date1 = new BanglaCalendar('2023-04-14'); // Latin digit
377
+ * const date2 = new BanglaCalendar(new Date('2023-04-14')); // Date object
378
+ *
379
+ * // Create with specific Bangla date using Latin digits
380
+ * const date3 = new BanglaCalendar(1430, 1, 1);
381
+ *
382
+ * // Create with specific Bangla date using Bangla digits
383
+ * const date4 = new BanglaCalendar('১৪৩০', '১', '১');
384
+ *
385
+ * // Create with specific variant
386
+ * const date5 = new BanglaCalendar('১৪৩০', '১', '১', { variant: 'revised-1966' });
387
+ *
388
+ * @remarks
389
+ * - The Bangla calendar year starts on `April 14th (১ বৈশাখ)` in the Gregorian calendar.
390
+ * - The class automatically handles leap years according to the selected variant.
391
+ */
392
+ var BanglaCalendar = class BanglaCalendar {
393
+ /** Bangla calendar variant */
394
+ variant;
395
+ /** Bangla year */
396
+ year;
397
+ /** Bangla month */
398
+ month;
399
+ /** Bangla day of the month */
400
+ date;
401
+ /** Gregorian equivalent of the current bangla date */
402
+ gregorian;
403
+ /** Gets the day of the week (0-6, where 0 is Sunday (রবিবার)). */
404
+ weekDay;
405
+ /** Gets ISO weekday: 1 = Monday, 7 = Sunday */
406
+ isoWeekDay;
407
+ /** * Creates a `BanglaCalendar` instance based on given parameter(s) */
408
+ constructor(dateBnYrOrCfg, bnMonthOrCfg, bnDateOrCfg, config) {
409
+ this.variant = this.#processVariants(dateBnYrOrCfg, bnMonthOrCfg, bnDateOrCfg, config);
410
+ let date = dateBnYrOrCfg instanceof Date ? dateBnYrOrCfg : new Date(isDateString(dateBnYrOrCfg) && !BanglaCalendar.isBanglaDateString(dateBnYrOrCfg) ? dateBnYrOrCfg : isNumber(dateBnYrOrCfg) && !BanglaCalendar.isBanglaYearEn(dateBnYrOrCfg) ? dateBnYrOrCfg : Date.now());
411
+ if (isNaN(date.getTime())) date = /* @__PURE__ */ new Date();
412
+ const { year, month, monthDate } = this.#processDate(date);
413
+ let bnYear = BanglaCalendar.isBanglaYear(dateBnYrOrCfg) ? banglaToDigit(dateBnYrOrCfg) : isNumber(dateBnYrOrCfg) && BanglaCalendar.isBanglaYearEn(dateBnYrOrCfg) ? dateBnYrOrCfg : year;
414
+ let bnMonth = BanglaCalendar.isBanglaMonth(bnMonthOrCfg) ? banglaToDigit(bnMonthOrCfg) : BanglaCalendar.isBanglaMonthEn(bnMonthOrCfg) ? bnMonthOrCfg : month;
415
+ let bnDate = BanglaCalendar.isBanglaDate(bnDateOrCfg) ? banglaToDigit(bnDateOrCfg) : BanglaCalendar.isBanglaDateEn(bnDateOrCfg) ? bnDateOrCfg : monthDate;
416
+ if (BanglaCalendar.isBanglaDateString(dateBnYrOrCfg)) {
417
+ const parts = dateBnYrOrCfg.replace(/['"]/g, "").split("-");
418
+ bnYear = banglaToDigit(parts[0]);
419
+ bnMonth = banglaToDigit(parts[1]);
420
+ bnDate = banglaToDigit(parts[2]);
421
+ }
422
+ const { gregYear } = this.#processGregYear(bnYear, bnMonth);
423
+ const { bnMonthTable } = this.#getBnMonthTableLeap(gregYear, bnYear);
424
+ const monthRange = bnMonthTable[bnMonth - 1];
425
+ if (bnDate > monthRange) {
426
+ bnDate -= monthRange;
427
+ if (bnMonth === 12) {
428
+ bnMonth = 1;
429
+ bnYear += 1;
430
+ } else bnMonth += 1;
431
+ }
432
+ this.year = {
433
+ bn: digitToBangla(bnYear),
434
+ en: bnYear
435
+ };
436
+ this.month = {
437
+ bn: digitToBangla(bnMonth),
438
+ en: bnMonth
439
+ };
440
+ this.date = {
441
+ bn: digitToBangla(bnDate),
442
+ en: bnDate
443
+ };
444
+ const { gy, gm, gd, wd } = _extractDateUnits(this.toDate());
445
+ this.gregorian = {
446
+ year: gy,
447
+ month: gm,
448
+ date: gd
449
+ };
450
+ this.weekDay = wd;
451
+ this.isoWeekDay = wd === 0 ? 7 : wd;
452
+ }
453
+ [Symbol.toPrimitive](hint) {
454
+ if (hint === "number") return this.valueOf();
455
+ return this.toJSON();
456
+ }
457
+ get [Symbol.toStringTag]() {
458
+ return this.toJSON();
459
+ }
460
+ /**
461
+ * @instance Get timestamp in milliseconds for the current date.
462
+ * @remarks
463
+ * - Converts the current Bangla date to a Gregorian {@link Date} using {@link toDate()}.
464
+ * - Returns the Unix timestamp (in milliseconds) of the converted date.
465
+ * - The time component is normalized to midnight UTC during the conversion process.
466
+ */
467
+ valueOf() {
468
+ return this.toDate().getTime();
469
+ }
470
+ /**
471
+ * @instance Returns a string representation of the Bangla date in ISO-like format (YYYY-MM-DD with Bangla digits).
472
+ *
473
+ * @returns Bangla date string in the format: "YYYY-MM-DD" (e.g., "১৪৩০-০১-০১")
474
+ *
475
+ * @example
476
+ * const bnCal = new BanglaCalendar('2023-04-14');
477
+ * console.log(bnCal.toJSON()); // "১৪৩০-০১-০১"
478
+ *
479
+ * @remarks
480
+ * - This method is automatically called by {@link JSON.stringify()} method
481
+ * - Output follows the pattern: `"বছর-মাস-দিন"` with zero-padded Bangla digits
482
+ * - Month and date are padded to 2 digits, year to 4 digits
483
+ */
484
+ toJSON() {
485
+ const { year, month, date } = this;
486
+ return `${_padShunno(year.bn, 4)}-${_padShunno(month.bn)}-${_padShunno(date.bn)}`;
487
+ }
488
+ /**
489
+ * * Checks if the current Bangla year is a leap year.
490
+ *
491
+ * @returns `true` if the year is a leap year, `false` otherwise
492
+ *
493
+ * @example
494
+ * const date = new BanglaCalendar(1430, 1, 1);
495
+ * const isLeap = date.isLeapYear(); // false
496
+ *
497
+ * @remarks
498
+ * - Leap year determination depends on the selected calendar variant.
499
+ * - The `'revised-2019'` and `'revised-1966'` variants have different leap year rules.
500
+ * - **Revised-2019**: Leap year is determined by the associated Gregorian year's leap rule:
501
+ * - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
502
+ * - **Revised-1966**: Leap year is determined solely by the Bangla year (`bnYear % 4 === 2`), no Gregorian rule applies.
503
+ */
504
+ isLeapYear() {
505
+ const { gregYear } = this.#processGregYear();
506
+ return this.#getBnMonthTableLeap(gregYear).isBnLeapYear;
507
+ }
508
+ /**
509
+ * * Converts the Bangla calendar date to a JS {@link Date} object.
510
+ *
511
+ * @returns Gregorian Date object equivalent to the Bangla date
512
+ *
513
+ * @example
514
+ * const bnDate = new BanglaCalendar('১৪৩০', '১', '১');
515
+ * const gregorianDate = bnDate.toDate(); // Date for April 14, 2023
516
+ * console.log(gregorianDate.toISOString()); // 2023-04-14T00:00:00.000Z
517
+ *
518
+ * @remarks
519
+ * - The conversion takes into account the calendar variant and leap year rules.
520
+ * - Time component is always set to `00:00:00` in UTC.
521
+ */
522
+ toDate() {
523
+ const { baseGregYear, gregYear } = this.#processGregYear();
524
+ const { bnMonthTable } = this.#getBnMonthTableLeap(gregYear);
525
+ const epoch = Date.UTC(baseGregYear, 3, 13);
526
+ let days = this.date.en;
527
+ for (let i = 0; i < this.month.en - 1; i++) days += bnMonthTable[i];
528
+ return new Date(days * MS_PER_DAY + epoch);
529
+ }
530
+ /**
531
+ * @instance Gets the Bangla season name for the current date.
532
+ *
533
+ * @param locale - Output locale ('bn' for Bengali, 'en' for English)
534
+ * @returns Name of the season in the specified locale
535
+ *
536
+ * @example
537
+ * const bnCal = new BanglaCalendar('2023-04-14');
538
+ * bnCal.getSeasonName(); // Returns: 'গ্রীষ্ম'
539
+ * bnCal.getSeasonName('en'); // Returns: 'Grisma (Summer)'
540
+ *
541
+ * @remarks
542
+ * Bangla calendar is traditionally divided into 6 seasons (ঋতু):
543
+ * - গ্রীষ্ম (Summer): Mid-April to Mid-June
544
+ * - বর্ষা (Monsoon): Mid-June to Mid-August
545
+ * - শরৎ (Autumn): Mid-August to Mid-October
546
+ * - হেমন্ত (Late Autumn): Mid-October to Mid-December
547
+ * - শীত (Winter): Mid-December to Mid-February
548
+ * - বসন্ত (Spring): Mid-February to Mid-April
549
+ */
550
+ getSeasonName(locale) {
551
+ return _getBnSeason(this.month.en - 1, locale);
552
+ }
553
+ /**
554
+ * @instance Gets the Bangla name of the month for the current date.
555
+ *
556
+ * @param locale - Output locale ('bn' for Bengali, 'en' for English)
557
+ * @returns Name of the month in the specified locale
558
+ *
559
+ * @example
560
+ * const bnCal = new BanglaCalendar('2023-04-14');
561
+ * bnCal.getMonthName(); // Returns: 'বৈশাখ'
562
+ * bnCal.getMonthName('en'); // Returns: 'Boishakh'
563
+ *
564
+ * @remarks
565
+ * - Month names follow traditional Bengali naming conventions.
566
+ * - English names are transliterated versions of the Bengali names.
567
+ * - Month determination may vary slightly between calendar variants near month boundaries.
568
+ */
569
+ getMonthName(locale) {
570
+ const MONTH = BN_MONTHS[this.month.en - 1];
571
+ return locale === "en" ? MONTH.en : MONTH.bn;
572
+ }
573
+ /**
574
+ * @instance Gets the Bangla name of the weekday for the current date.
575
+ *
576
+ * @param locale - Output locale ('bn' for Bengali, 'en' for English)
577
+ * @returns Name of the weekday in the specified locale
578
+ *
579
+ * @example
580
+ * const bnCal = new BanglaCalendar('2023-04-14'); // Friday
581
+ * bnCal.getDayName(); // Returns: 'শুক্রবার'
582
+ * bnCal.getDayName('en'); // Returns: 'Shukrobar (Friday)'
583
+ *
584
+ * @remarks
585
+ * - Weekday names follow the standard Bengali naming convention ending with 'বার'.
586
+ * - English names are the Latin transliterations of the Bangla names with standard English weekday names.
587
+ */
588
+ getDayName(locale) {
589
+ const DAY = BN_DAYS[this.weekDay];
590
+ return locale === "en" ? DAY.en : DAY.bn;
591
+ }
592
+ /**
593
+ * @instance Adds days to the current Bangla date.
594
+ *
595
+ * @param days - Number of days to add (can be negative to subtract days)
596
+ * @returns New `BanglaCalendar` instance with the adjusted date
597
+ *
598
+ * @example
599
+ * const bnCal = new BanglaCalendar('১৪৩০', '১', '১'); // ১ বৈশাখ ১৪৩০
600
+ *
601
+ * // Add days
602
+ * bnCal.addDays(7); // Returns: ৮ বৈশাখ ১৪৩০
603
+ *
604
+ * // Subtract days
605
+ * bnCal.addDays(-3); // Returns: ২৮ চৈত্র ১৪২৯
606
+ *
607
+ * // Add days crossing month boundary
608
+ * bnCal.addDays(35); // Returns: ৫ জ্যৈষ্ঠ ১৪৩০
609
+ *
610
+ * // Add days crossing year boundary
611
+ * const lateDate = new BanglaCalendar('১৪৩০', '১২', '২৫');
612
+ * lateDate.addDays(10); // Returns: ৫ বৈশাখ ১৪৩১
613
+ *
614
+ * @remarks
615
+ * - The resulting instance preserves the calendar variant of the original
616
+ * - Handles month and year transitions automatically
617
+ * - Accounts for varying month lengths and leap years
618
+ * - Time component remains at midnight UTC in the Gregorian conversion (using {@link BanglaCalendar.toDate()} method)
619
+ * - Negative values subtract days from the current date
620
+ */
621
+ addDays(days) {
622
+ const date = this.toDate();
623
+ return new BanglaCalendar(date.setDate(date.getDate() + days), { variant: this.variant });
624
+ }
625
+ /**
626
+ * @instance Adds weeks to the current Bangla date.
627
+ *
628
+ * @param weeks - Number of weeks to add (can be negative to subtract weeks)
629
+ * @returns New `BanglaCalendar` instance with the adjusted date
630
+ *
631
+ * @example
632
+ * const bnCal = new BanglaCalendar('১৪৩০', '১', '১'); // ১ বৈশাখ ১৪৩০
633
+ *
634
+ * // Add weeks
635
+ * bnCal.addWeeks(2); // Returns: ১৫ বৈশাখ ১৪৩০
636
+ *
637
+ * // Subtract weeks
638
+ * bnCal.addWeeks(-1); // Returns: ২৪ চৈত্র ১৪২৯
639
+ *
640
+ * // Add weeks crossing month boundary
641
+ * bnCal.addWeeks(5); // Returns: ৫ জ্যৈষ্ঠ ১৪৩০
642
+ *
643
+ * @remarks
644
+ * - Each week is treated as 7 days
645
+ * - The resulting instance preserves the calendar variant of the original
646
+ * - Handles month and year transitions automatically
647
+ * - Time component remains at midnight UTC in the Gregorian conversion (using {@link BanglaCalendar.toDate()} method)
648
+ * - Negative values subtract weeks from the current date
649
+ * - Useful for scheduling recurring weekly events
650
+ */
651
+ addWeeks(weeks) {
652
+ const date = this.toDate();
653
+ return new BanglaCalendar(date.setDate(date.getDate() + weeks * 7), { variant: this.variant });
654
+ }
655
+ /**
656
+ * @instance Adds months to the current Bangla date.
657
+ *
658
+ * @param months - Number of months to add (can be negative to subtract months)
659
+ * @param overflow - If `true`, allows date overflow to next month when day doesn't exist;
660
+ * if `false`, clamps to last day of target month (default: `true`)
661
+ * @returns New `BanglaCalendar` instance with the adjusted date
662
+ *
663
+ * @example
664
+ * // Normal case: day exists in target month
665
+ * const normal = new BanglaCalendar('১৪৩০', '২', '১৫');
666
+ * normal.addMonths(1); // Returns: ১৫ আষাঢ় ১৪৩০
667
+ * normal.addMonths(1, false); // Returns: ১৫ আষাঢ় ১৪৩০ (same behavior for both)
668
+ *
669
+ * // Edge case: day does not exist in target month
670
+ * const edgeCase = new BanglaCalendar('১৪৩০', '৬', '৩১'); // ৩১ আশ্বিন ১৪৩০
671
+ *
672
+ * // With overflow (default): 31st doesn't exist in কার্তিক (30 days)
673
+ * edgeCase.addMonths(1); // Returns: ১ অগ্রহায়ণ ১৪৩০ (overflows to next month)
674
+ *
675
+ * // Without overflow: clamps to last day of target month
676
+ * edgeCase.addMonths(1, false); // Returns: ৩০ কার্তিক ১৪৩০ (clamped)
677
+ *
678
+ * // Subtract months
679
+ * edgeCase.addMonths(-1); // Returns: ১ আশ্বিন ১৪৩০
680
+ * edgeCase.addMonths(-1, false); // Returns: ৩১ ভাদ্র ১৪৩০
681
+ *
682
+ * @remarks
683
+ * - When `overflow=true` (default):
684
+ * Follows JavaScript {@link Date} behavior where invalid dates overflow to the next month (e.g., ৩১ আশ্বিন + 1 month → ১ অগ্রহায়ণ)
685
+ * - When `overflow=false`:
686
+ * Clamps to the last valid day of the target month (e.g., ৩১ আশ্বিন + 1 month → ৩০ কার্তিক)
687
+ * - The resulting instance preserves the calendar variant of the original
688
+ * - Handles year transitions automatically
689
+ * - Time component remains at midnight UTC in the Gregorian conversion (using {@link BanglaCalendar.toDate()} method)
690
+ * - Negative values subtract months from the current date
691
+ */
692
+ addMonths(months, overflow = true) {
693
+ if (overflow) {
694
+ const current = this.toDate();
695
+ return new BanglaCalendar(current.setMonth(current.getMonth() + months), { variant: this.variant });
696
+ } else {
697
+ const { variant, year, month, date } = this;
698
+ let targetMonth = month.en + months;
699
+ let targetYear = year.en;
700
+ while (targetMonth > 12) {
701
+ targetMonth -= 12;
702
+ targetYear += 1;
703
+ }
704
+ while (targetMonth < 1) {
705
+ targetMonth += 12;
706
+ targetYear -= 1;
707
+ }
708
+ return this.#getClampedBnCal(targetYear, targetMonth, date.en, variant);
709
+ }
710
+ }
711
+ /**
712
+ * @instance Adds years to the current Bangla date.
713
+ *
714
+ * @param years - Number of years to add (can be negative to subtract years)
715
+ * @param overflow - If `true`, allows date overflow when day doesn't exist in target year;
716
+ * if `false`, clamps to last valid day of month (default: `true`)
717
+ * @returns New `BanglaCalendar` instance with the adjusted date
718
+ *
719
+ * @example
720
+ * const bnCal = new BanglaCalendar('১৪৩০', '১', '১৫'); // ১৫ বৈশাখ ১৪৩০
721
+ *
722
+ * // Add years
723
+ * bnCal.addYears(1); // Returns: ১৫ বৈশাখ ১৪৩১
724
+ *
725
+ * // Subtract years
726
+ * bnCal.addYears(-1); // Returns: ১৫ বৈশাখ ১৪২৯
727
+ *
728
+ * // Multiple years
729
+ * bnCal.addYears(5); // Returns: ১৫ বৈশাখ ১৪৩৫
730
+ *
731
+ * // Edge case: day adjustment for ফাল্গুন (accounting leap year)
732
+ * const leapDay = new BanglaCalendar('১৪৩১', '১১', '৩০'); // ১৪৩১ is a leap year
733
+ * leapDay.addYears(1, false); // Returns: ২৯ ফাল্গুন ১৪৩২ (non-leap years have 29 days in ফাল্গুন)
734
+ *
735
+ * @remarks
736
+ * - The resulting instance preserves the calendar variant of the original
737
+ * - Negative values subtract years from the current date
738
+ * - Year addition follows Bangla calendar years
739
+ * - Time component remains at midnight UTC in the Gregorian conversion (using {@link BanglaCalendar.toDate()} method)
740
+ * - The month and day generally remain the same unless affected by leap year rules
741
+ */
742
+ addYears(years, overflow = true) {
743
+ const { variant, year, month, date } = this;
744
+ const targetYear = year.en + years;
745
+ if (overflow) return new BanglaCalendar(targetYear, month.en, date.en, { variant });
746
+ else return this.#getClampedBnCal(targetYear, month.en, date.en, variant);
747
+ }
748
+ /**
749
+ * @instance Gets a new `BanglaCalendar` instance representing the first day of the current month.
750
+ *
751
+ * @returns A `BanglaCalendar` instance set to the 1st day of the current month
752
+ *
753
+ * @example
754
+ * const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
755
+ * const startOfMonth = bnCal.startOfMonth(); // Returns: ১ জ্যৈষ্ঠ ১৪৩০
756
+ *
757
+ * @remarks
758
+ * - The resulting instance preserves the calendar variant of the original
759
+ * - Useful for date range calculations and month-based operations
760
+ * - Time component remains at midnight UTC in the Gregorian conversion (using {@link BanglaCalendar.toDate()} method)
761
+ */
762
+ startOfMonth() {
763
+ const { year, month, variant } = this;
764
+ return new BanglaCalendar(year.en, month.en, 1, { variant });
765
+ }
766
+ /**
767
+ * @instance Gets a new `BanglaCalendar` instance representing the last day of the current month.
768
+ *
769
+ * @returns A `BanglaCalendar` instance set to the last day of the current month
770
+ *
771
+ * @example
772
+ * const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
773
+ * const endOfMonth = bnCal.endOfMonth(); // Returns: ৩১ জ্যৈষ্ঠ ১৪৩০ (or 30 for some months)
774
+ *
775
+ * @remarks
776
+ * - The resulting instance preserves the calendar variant of the original
777
+ * - Accounts for month length variations (29/30/31 days) including leap years
778
+ * - Time component remains at midnight UTC in the Gregorian conversion (using {@link BanglaCalendar.toDate()} method)
779
+ */
780
+ endOfMonth() {
781
+ const { year, month, variant } = this;
782
+ return new BanglaCalendar(year.en, month.en, this.daysInMonth(), { variant });
783
+ }
784
+ /**
785
+ * @instance Gets a new `BanglaCalendar` instance representing the first day of the current year (১ বৈশাখ).
786
+ *
787
+ * @returns A `BanglaCalendar` instance set to ১ বৈশাখ of the current year
788
+ *
789
+ * @example
790
+ * const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
791
+ * const startOfYear = bnCal.startOfYear(); // Returns: ১ বৈশাখ ১৪৩০
792
+ *
793
+ * @remarks
794
+ * - The resulting instance preserves the calendar variant of the original
795
+ * - Always returns the 1st day of the 1st month (বৈশাখ)
796
+ * - Time component remains at midnight UTC in the Gregorian conversion (using {@link BanglaCalendar.toDate()} method)
797
+ */
798
+ startOfYear() {
799
+ const { year, variant } = this;
800
+ return new BanglaCalendar(year.en, 1, 1, { variant });
801
+ }
802
+ /**
803
+ * @instance Gets a new `BanglaCalendar` instance representing the last day of the current year (৩০ চৈত্র).
804
+ *
805
+ * @returns A `BanglaCalendar` instance set to ৩০ চৈত্র of the current year
806
+ *
807
+ * @example
808
+ * const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
809
+ * const endOfYear = bnCal.endOfYear(); // Returns: ৩০ চৈত্র ১৪৩০
810
+ *
811
+ * @remarks
812
+ * - The resulting instance preserves the calendar variant of the original
813
+ * - Always returns the 30th day of the 12th month (চৈত্র)
814
+ * - Time component remains at midnight UTC in the Gregorian conversion (using {@link BanglaCalendar.toDate()} method)
815
+ */
816
+ endOfYear() {
817
+ const { year, variant } = this;
818
+ return new BanglaCalendar(year.en, 12, 30, { variant });
819
+ }
820
+ /**
821
+ * @instance Gets the number of days in a Bangla month.
822
+ *
823
+ * @param month - Optional Bangla month (1-12 in Latin digits)
824
+ * @returns Number of days in the specified month (29, 30, or 31)
825
+ *
826
+ * @example
827
+ * const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
828
+ *
829
+ * // Get days in current month
830
+ * bnCal.daysInMonth(); // Returns: 31 (বৈশাখ has 31 days)
831
+ *
832
+ * // Get days in specific month
833
+ * bnCal.daysInMonth(2); // Returns: 31 (জ্যৈষ্ঠ has 31 days)
834
+ * bnCal.daysInMonth(12); // Returns: 30 (চৈত্র has 30 days)
835
+ *
836
+ * @remarks
837
+ * - The method accounts for the selected calendar variant when determining leap years
838
+ * - If no month is provided, uses the current instance's month
839
+ * - In the 'revised-2019' variant, leap years follow Gregorian leap rules
840
+ * - In the 'revised-1966' variant, leap years occur when `bnYear % 4 === 2`
841
+ */
842
+ daysInMonth(month) {
843
+ const { gregYear } = this.#processGregYear();
844
+ const { bnMonthTable } = this.#getBnMonthTableLeap(gregYear);
845
+ return bnMonthTable[(month ?? this.month.en) - 1];
846
+ }
847
+ /**
848
+ * @instance Returns a string representation of the Bangla date in Bengali format.
849
+ *
850
+ * @returns Bangla date string in the format: "শুক্রবার, ১৫ জ্যৈষ্ঠ, ১৪৩০ [গ্রীষ্ম]"
851
+ *
852
+ * @example
853
+ * const bnCal = new BanglaCalendar('2023-04-14');
854
+ * console.log(bnCal.toString()); // "শুক্রবার, ১ বৈশাখ, ১৪৩০ [গ্রীষ্ম]"
855
+ *
856
+ * @remarks
857
+ * - Equivalent to calling {@link toStringEn()} with 'bn' locale
858
+ * - Format includes day name, date, month name, year, and season in brackets
859
+ * - Uses Bengali digits and Bengali month/day names
860
+ */
861
+ toString() {
862
+ return this.#toString("bn");
863
+ }
864
+ /**
865
+ * @instance Returns a string representation of the Bangla date in English/Latin format.
866
+ *
867
+ * @returns Bangla date string in the format: "Shukrobar (Friday), 15 Joishtho, 1430 [Grisma (Summer)]"
868
+ *
869
+ * @example
870
+ * const bnCal = new BanglaCalendar('2023-04-14');
871
+ * console.log(bnCal.toStringEn()); // "Shukrobar (Friday), 1 Boishakh, 1430 [Grisma (Summer)]"
872
+ *
873
+ * @remarks
874
+ * - Equivalent to calling {@link toString()} with 'en' locale
875
+ * - Format includes transliterated day name (with English equivalent), date, transliterated month and season name, and year.
876
+ * - Uses Latin digits and transliterated Bengali names
877
+ */
878
+ toStringEn() {
879
+ return this.#toString("en");
880
+ }
881
+ /**
882
+ * @instance Formats the current date as a Bangla calendar date string (no time) using customizable tokens.
883
+ *
884
+ * @param format - Format string using tokens (default: `'ddd, DD mmmm (SS), YYYY বঙ্গাব্দ'`)
885
+ * @returns Formatted Bangla date string according to the specified format
886
+ *
887
+ * @example
888
+ * const bnCal = new BanglaCalendar('2023-04-14');
889
+ *
890
+ * bnCal.format();
891
+ * // Returns: 'শুক্রবার, বৈশাখ ০১ (গ্রীষ্মকাল), ১৪৩০ বঙ্গাব্দ'
892
+ *
893
+ * bnCal.format('YYYY-MM-DD');
894
+ * // Returns: '১৪৩০-০১-০১'
895
+ *
896
+ * bnCal.format('mmmm DD, YYYY');
897
+ * // Returns: 'বৈশাখ ০১, ১৪৩০'
898
+ *
899
+ * @remarks
900
+ * - **Important:** Does not allow time formatting tokens!
901
+ * - Supported format tokens include: `YYYY`, `YY`, `mmmm`, `mmm`, `MM`, `M`, `DD`, `D`, `dd`, `ddd`, `Do`, `SS` and `S`.
902
+ * - **Year**: `YYYY/yyyy` (full year), `YY/yy` (last 2 digits)
903
+ * - **Month**: `M/MM`(padded), `mmm` (short name), `mmmm` (full name)
904
+ * - **Day**: `D/DD`(padded), Do (results same as cardinal for Bangla dates)
905
+ * - **Weekday**: `d` (short), `dd` (without 'বার'), `ddd` (full)
906
+ * - **Season**: `S` (season), `SS` (season with 'কাল' suffix)
907
+ * - To output raw text (i.e., not interpreted as a date token), wrap it in square brackets.
908
+ * - For example, `[আজ] ddd` results in `আজ রবিবার`, and `[year ]YYYY` results in `year ২০২৫`.
909
+ * - *Any token not wrapped in brackets will be parsed and replaced with its corresponding date component.*
910
+ */
911
+ format(format) {
912
+ const { year, month, date, weekDay } = this;
913
+ const seasonName = this.getSeasonName();
914
+ const M_NAME = BN_MONTHS[month.en - 1];
915
+ const D_NAME = BN_DAYS[weekDay];
916
+ const paddedYear = _padShunno(year.bn, 4);
917
+ const dateComponents = {
918
+ YYYY: paddedYear,
919
+ YY: paddedYear.slice(-2),
920
+ yyyy: paddedYear,
921
+ yy: paddedYear.slice(-2),
922
+ M: month.bn,
923
+ MM: _padShunno(month.bn),
924
+ mmm: M_NAME.short,
925
+ mmmm: M_NAME.bn,
926
+ d: D_NAME.short,
927
+ dd: D_NAME.bn.replace("বার", ""),
928
+ ddd: D_NAME.bn,
929
+ D: date.bn,
930
+ DD: _padShunno(date.bn),
931
+ Do: date.bn,
932
+ S: seasonName,
933
+ SS: seasonName + "কাল"
934
+ };
935
+ return _formatDateCore(format || "ddd, DD mmmm (SS), YYYY বঙ্গাব্দ", dateComponents);
936
+ }
937
+ /** Process Gregorian base year and calculated year from optional Bangla year and month */
938
+ #processGregYear(bnYear, bnMonth) {
939
+ const baseGregYear = (bnYear ?? this.year.en) + 593;
940
+ return {
941
+ baseGregYear,
942
+ gregYear: (bnMonth ?? this.month.en) > 10 ? baseGregYear + 1 : baseGregYear
943
+ };
944
+ }
945
+ /** Get the Bangla month table and leap year flag based on calendar variant */
946
+ #getBnMonthTableLeap(gregYear, bnYear) {
947
+ const isBnLeapYear = _isBnLeapYear(bnYear ?? this.year.en, gregYear, this.variant);
948
+ return {
949
+ bnMonthTable: isBnLeapYear ? BN_MONTH_TABLES?.[this.variant].leap : BN_MONTH_TABLES?.[this.variant].normal,
950
+ isBnLeapYear
951
+ };
952
+ }
953
+ /**
954
+ * @internal Get new `BanglaCalendar` instance with clamped date
955
+ * @param tyBn - Target Bangla year
956
+ * @param tmBn - Target Bangla month
957
+ * @param cdBn - Current Bangla date of the month
958
+ * @param variant - Calendar variant to preserve
959
+ * @returns New `BanglaCalendar` instance with date clamped to valid range
960
+ *
961
+ * @remarks
962
+ * - Clamps the date to not exceed the number of days in the target month
963
+ * - Used internally for non-overflow date arithmetic
964
+ * - Ensures dates like ৩১ don't become invalid in months with only 30 days
965
+ */
966
+ #getClampedBnCal(tyBn, tmBn, cdBn, variant) {
967
+ const { gregYear } = this.#processGregYear(tyBn, tmBn);
968
+ const { bnMonthTable } = this.#getBnMonthTableLeap(gregYear, tyBn);
969
+ return new BanglaCalendar(tyBn, tmBn, Math.min(cdBn, bnMonthTable[tmBn - 1]), { variant });
970
+ }
971
+ /** Process variant from the config */
972
+ #processVariants(v1, v2, v3, v4) {
973
+ return this.$hasVariantConfig(v1) ? v1.variant : this.$hasVariantConfig(v2) ? v2.variant : this.$hasVariantConfig(v3) ? v3.variant : this.$hasVariantConfig(v4) ? v4.variant : "revised-2019";
974
+ }
975
+ /** Process {@link Date} and extract Bangla year, month and dates in both Bangla and Latin */
976
+ #processDate(date) {
977
+ const bnYear = _getBnYear(date);
978
+ const { days, monthIdx } = _bnDaysMonthIdx(date, this.variant);
979
+ return {
980
+ year: bnYear,
981
+ month: monthIdx + 1,
982
+ monthDate: days + 1
983
+ };
984
+ }
985
+ /** Convert to human readable string either in `bn` or `en` locale */
986
+ #toString(lcl = "bn") {
987
+ const { year, date } = this;
988
+ return `${this.getDayName(lcl)}, ${date[lcl]} ${this.getMonthName(lcl)}, ${year[lcl]} [${this.getSeasonName(lcl)}]`;
989
+ }
990
+ /**
991
+ * @static Check if a value is a configuration object that contains a valid {@link variant}
992
+ * @param value Value to check
993
+ * @returns `true` if the value contains a valid {@link variant} property, `false` otherwise
994
+ */
995
+ $hasVariantConfig(value) {
996
+ return isObjectWithKeys(value, ["variant"]) && isNonEmptyString(value.variant) && (value.variant === "revised-1966" || value.variant === "revised-2019");
997
+ }
998
+ /**
999
+ * @static Checks whether a value is a valid Bangla year in Bangla digits (`০–৯৯৯৯`).
1000
+ *
1001
+ * @param value - Value to check. Accepts both zero-padded and non-padded Bangla digits
1002
+ * @returns `true` if the value is a valid Bangla year, `false` otherwise
1003
+ *
1004
+ * @example
1005
+ * BanglaCalendar.isBanglaYear('১৪৩০'); // true
1006
+ * BanglaCalendar.isBanglaYear('০'); // true
1007
+ * BanglaCalendar.isBanglaYear('১০০০০'); // false (too many digits)
1008
+ * BanglaCalendar.isBanglaYear('1430'); // false (Latin digits)
1009
+ */
1010
+ static isBanglaYear(value) {
1011
+ return isNonEmptyString(value) && /^(?:০{0,3}[১-৯][০-৯]{0,3}|০)$/.test(value.trim());
1012
+ }
1013
+ /**
1014
+ * @static Checks whether a value is a valid Bangla year in Latin digits (`0–9999`).
1015
+ *
1016
+ * @param value - Value to check (must be a number)
1017
+ * @returns `true` if the value is a valid Bangla year, `false` otherwise
1018
+ *
1019
+ * @example
1020
+ * BanglaCalendar.isBanglaYearEn(1430); // true
1021
+ * BanglaCalendar.isBanglaYearEn(0); // true
1022
+ * BanglaCalendar.isBanglaYearEn(10000); // false
1023
+ * BanglaCalendar.isBanglaYearEn(-1); // false
1024
+ */
1025
+ static isBanglaYearEn(value) {
1026
+ return isInteger(value) && value >= 0 && value <= 9999;
1027
+ }
1028
+ /**
1029
+ * @static Checks whether a value is a valid Bangla month in Bangla digits (`১–১২`).
1030
+ *
1031
+ * @param value - Value to check. Accepts both zero-padded and non-padded Bangla digits
1032
+ * @returns `true` if the value is a valid Bangla month, `false` otherwise
1033
+ *
1034
+ * @example
1035
+ * BanglaCalendar.isBanglaMonth('১'); // true
1036
+ * BanglaCalendar.isBanglaMonth('১২'); // true
1037
+ * BanglaCalendar.isBanglaMonth('১৩'); // false
1038
+ * BanglaCalendar.isBanglaMonth('0'); // false (Latin digit)
1039
+ */
1040
+ static isBanglaMonth(value) {
1041
+ return isNonEmptyString(value) && /^(?:০?[১-৯]|১০|১১|১২)$/.test(value.trim());
1042
+ }
1043
+ /**
1044
+ * @static Checks whether a value is a valid Bangla month in Latin digits (`1–12`).
1045
+ *
1046
+ * @param value - Value to check
1047
+ * @returns `true` if the value is a valid Bangla month, `false` otherwise
1048
+ *
1049
+ * @example
1050
+ * BanglaCalendar.isBanglaMonthEn(1); // true
1051
+ * BanglaCalendar.isBanglaMonthEn(12); // true
1052
+ * BanglaCalendar.isBanglaMonthEn(0); // false
1053
+ * BanglaCalendar.isBanglaMonthEn(13); // false
1054
+ */
1055
+ static isBanglaMonthEn(value) {
1056
+ return isInteger(value) && value >= 1 && value <= 12;
1057
+ }
1058
+ /**
1059
+ * @static Checks whether a value is a valid Bangla date of month in Bangla digits (`১–৩১`).
1060
+ *
1061
+ * @param value - Value to check. Accepts both zero-padded and non-padded Bangla digits
1062
+ * @returns `true` if the value is a valid Bangla date, `false` otherwise
1063
+ *
1064
+ * @example
1065
+ * BanglaCalendar.isBanglaDate('১'); // true
1066
+ * BanglaCalendar.isBanglaDate('৩১'); // true
1067
+ * BanglaCalendar.isBanglaDate('৩২'); // false
1068
+ * BanglaCalendar.isBanglaDate('০'); // false
1069
+ */
1070
+ static isBanglaDate(value) {
1071
+ return isNonEmptyString(value) && /^(?:০?[১-৯]|[১২][০-৯]|৩০|৩১)$/.test(value.trim());
1072
+ }
1073
+ /**
1074
+ * @static Checks whether a value is a valid Bangla date of month in Latin digits (`1–31`).
1075
+ *
1076
+ * @param value - Value to check
1077
+ * @returns `true` if the value is a valid Bangla date, `false` otherwise
1078
+ *
1079
+ * @example
1080
+ * BanglaCalendar.isBanglaDateEn(1); // true
1081
+ * BanglaCalendar.isBanglaDateEn(31); // true
1082
+ * BanglaCalendar.isBanglaDateEn(32); // false
1083
+ * BanglaCalendar.isBanglaDateEn(0); // false
1084
+ */
1085
+ static isBanglaDateEn(value) {
1086
+ return isInteger(value) && value >= 1 && value <= 31;
1087
+ }
1088
+ /**
1089
+ * @static Checks whether a string follows the Bangla date format pattern (`YYYY-MM-DD` with Bangla digits).
1090
+ *
1091
+ * @param value - String value to check
1092
+ * @returns `true` if the string matches the pattern `"বছর-মাস-দিন"` with Bangla digits, `false` otherwise
1093
+ *
1094
+ * @example
1095
+ * BanglaCalendar.isBanglaDateString('১৪৩০-০১-০১'); // true
1096
+ * BanglaCalendar.isBanglaDateString('1430-01-01'); // false (Latin digits)
1097
+ * BanglaCalendar.isBanglaDateString('১৪৩০-১-১'); // true (single-digit month/date)
1098
+ * BanglaCalendar.isBanglaDateString('১৪৩০-১৩-০১'); // false (invalid month)
1099
+ *
1100
+ * @remarks
1101
+ * - Accepts both zero-padded and non-padded Bangla digits
1102
+ * - Validates year, month, and date components separately
1103
+ * - Year must be `‌০-৯৯৯৯`, month must be `১-১২`, date must be `১-৩১`
1104
+ */
1105
+ static isBanglaDateString(value) {
1106
+ if (isNonEmptyString(value) && value.includes("-")) {
1107
+ const [year, month, date] = value.replace(/['"]/g, "").split("-");
1108
+ return BanglaCalendar.isBanglaYear(year) && BanglaCalendar.isBanglaMonth(month) && BanglaCalendar.isBanglaDate(date);
1109
+ }
1110
+ return false;
1111
+ }
1112
+ };
1113
+
1114
+ //#endregion
1115
+ export { BanglaCalendar, BanglaCalendar as BnCalendar, BanglaCalendar as Bongabdo };