bn-calendar 1.2.1 → 1.2.2

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