bn-calendar 1.0.1

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