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