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/README.md +399 -379
- package/dist/convert-BetQIRvF.cjs +128 -0
- package/dist/convert-CYpIfNZ_.mjs +80 -0
- package/dist/index.cjs +1102 -1
- package/dist/index.mjs +1099 -1
- package/dist/types.mjs +1 -1
- package/dist/utils.cjs +5 -1
- package/dist/utils.mjs +3 -1
- package/package.json +11 -5
- package/dist/convert-3jw8Rx7e.cjs +0 -1
- package/dist/convert-Byg6yAIU.mjs +0 -1
package/README.md
CHANGED
|
@@ -85,17 +85,109 @@ yarn add bn-calendar
|
|
|
85
85
|
|
|
86
86
|
## Import
|
|
87
87
|
|
|
88
|
-
```
|
|
89
|
-
// Main class
|
|
88
|
+
```typescript
|
|
90
89
|
import { BanglaCalendar } from 'bn-calendar';
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Table of Contents
|
|
95
|
+
|
|
96
|
+
- [Quick Examples](#quick-examples)
|
|
97
|
+
- [API Reference](#api-reference)
|
|
98
|
+
- [Constructor](#constructor)
|
|
99
|
+
- [Constructor Signatures](#constructor-signatures)
|
|
100
|
+
- [Parameters](#parameters)
|
|
101
|
+
- [Behavior](#behavior)
|
|
102
|
+
- [Examples](#examples)
|
|
103
|
+
- [Properties](#properties)
|
|
104
|
+
- [variant](#variant)
|
|
105
|
+
- [year](#year)
|
|
106
|
+
- [month](#month)
|
|
107
|
+
- [date](#date)
|
|
108
|
+
- [gregorian](#gregorian)
|
|
109
|
+
- [weekDay](#weekday)
|
|
110
|
+
- [isoWeekDay](#isoweekday)
|
|
111
|
+
- [Instance Methods](#instance-methods)
|
|
112
|
+
- [format()](#format)
|
|
113
|
+
- [valueOf()](#valueof)
|
|
114
|
+
- [isLeapYear()](#isleapyear)
|
|
115
|
+
- [toDate()](#todate)
|
|
116
|
+
- [getSeasonName()](#getseasonname)
|
|
117
|
+
- [getMonthName()](#getmonthname)
|
|
118
|
+
- [getDayName()](#getdayname)
|
|
119
|
+
- [startOfMonth()](#startofmonth)
|
|
120
|
+
- [endOfMonth()](#endofmonth)
|
|
121
|
+
- [startOfYear()](#startofyear)
|
|
122
|
+
- [endOfYear()](#endofyear)
|
|
123
|
+
- [daysInMonth()](#daysinmonth)
|
|
124
|
+
- [toJSON()](#tojson)
|
|
125
|
+
- [toString()](#tostring)
|
|
126
|
+
- [toStringEn()](#tostringen)
|
|
127
|
+
- [addDays()](#adddays)
|
|
128
|
+
- [addWeeks()](#addweeks)
|
|
129
|
+
- [addMonths()](#addmonths)
|
|
130
|
+
- [addYears()](#addyears)
|
|
131
|
+
- [$hasVariantConfig()](#hasvariantconfig)
|
|
132
|
+
- [Static Methods](#static-methods)
|
|
133
|
+
- [isBanglaYear()](#isbanglayear)
|
|
134
|
+
- [isBanglaYearEn()](#isbanglayearen)
|
|
135
|
+
- [isBanglaMonth()](#isbanglamonth)
|
|
136
|
+
- [isBanglaMonthEn()](#isbanglamonthen)
|
|
137
|
+
- [isBanglaDate()](#isbangladate)
|
|
138
|
+
- [isBanglaDateEn()](#isbangladateen)
|
|
139
|
+
- [isBanglaDateString()](#isbangladatestring)
|
|
140
|
+
- [Symbol Methods](#symbol-methods)
|
|
141
|
+
- [[Symbol.toPrimitive]](#symboltoprimitive)
|
|
142
|
+
- [[Symbol.toStringTag]](#symboltostringtag)
|
|
143
|
+
- [Detailed Examples](#detailed-examples)
|
|
144
|
+
- [Basic Usage](#basic-usage)
|
|
145
|
+
- [Date Conversion](#date-conversion)
|
|
146
|
+
- [Month Operations](#month-operations)
|
|
147
|
+
- [Aliases](#aliases)
|
|
148
|
+
- [Type Definitions](#type-definitions)
|
|
149
|
+
- [Bangla Digit Conversion Utilities](#bangla-digit-conversion-utilities)
|
|
150
|
+
- [Import](#import)
|
|
151
|
+
- [banglaToDigit()](#banglatodigit)
|
|
152
|
+
- [digitToBangla()](#digittobangla)
|
|
153
|
+
- [Type Definitions](#type-definitions-1)
|
|
154
|
+
- [Related Packages](#-related-packages)
|
|
155
|
+
- [License](#license)
|
|
91
156
|
|
|
92
|
-
|
|
93
|
-
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Quick Examples
|
|
160
|
+
|
|
161
|
+
**`BanglaCalendar`** - The class to create, manipulate, and convert dates between the Bangla and Gregorian calendar systems.
|
|
162
|
+
|
|
163
|
+
> It supports two calendar variants: `'revised-2019'` (default) and `'revised-1966'`.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
// Create from current date
|
|
167
|
+
const today = new BanglaCalendar();
|
|
168
|
+
|
|
169
|
+
// Create from Bangla date string (Bangla digit)
|
|
170
|
+
const date0 = new BanglaCalendar('১৪৩২-১১-০৮');
|
|
171
|
+
|
|
172
|
+
// Create from Gregorian date
|
|
173
|
+
const date1 = new BanglaCalendar('2023-04-14'); // Latin digit
|
|
174
|
+
const date2 = new BanglaCalendar(new Date('2023-04-14')); // Date object
|
|
175
|
+
|
|
176
|
+
// Create with specific Bangla date using Latin digits
|
|
177
|
+
const date3 = new BanglaCalendar(1430, 1, 1);
|
|
178
|
+
|
|
179
|
+
// Create with specific Bangla date using Bangla digits
|
|
180
|
+
const date4 = new BanglaCalendar('১৪৩০', '১', '১');
|
|
181
|
+
|
|
182
|
+
// Create with specific variant
|
|
183
|
+
const date5 = new BanglaCalendar('১৪৩০', '১', '১', { variant: 'revised-1966' });
|
|
94
184
|
```
|
|
95
185
|
|
|
96
186
|
---
|
|
97
187
|
|
|
98
|
-
##
|
|
188
|
+
## API Reference
|
|
189
|
+
|
|
190
|
+
### Constructor
|
|
99
191
|
|
|
100
192
|
Creates a new `BanglaCalendar` instance from various input formats.
|
|
101
193
|
|
|
@@ -208,49 +300,9 @@ new BanglaCalendar('১৪৩০', '১', '১', { variant: 'revised-1966' });
|
|
|
208
300
|
|
|
209
301
|
---
|
|
210
302
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
- **Instance Methods**
|
|
214
|
-
- [valueOf](#valueof)
|
|
215
|
-
- [isLeapYear](#isleapyear)
|
|
216
|
-
- [toDate](#todate)
|
|
217
|
-
- [getSeasonName](#getseasonname)
|
|
218
|
-
- [getMonthName](#getmonthname)
|
|
219
|
-
- [getDayName](#getdayname)
|
|
220
|
-
- [startOfMonth](#startofmonth)
|
|
221
|
-
- [endOfMonth](#endofmonth)
|
|
222
|
-
- [startOfYear](#startofyear)
|
|
223
|
-
- [endOfYear](#endofyear)
|
|
224
|
-
- [daysInMonth](#daysinmonth)
|
|
225
|
-
- [toJSON](#tojson)
|
|
226
|
-
- [toString](#tostring)
|
|
227
|
-
- [toStringEn](#tostringen)
|
|
228
|
-
- [format](#format)
|
|
229
|
-
- [addDays](#adddays)
|
|
230
|
-
- [addWeeks](#addweeks)
|
|
231
|
-
- [addMonths](#addmonths)
|
|
232
|
-
- [addYears](#addyears)
|
|
233
|
-
- [$hasVariantConfig](#hasvariantconfig)
|
|
234
|
-
|
|
235
|
-
- **Static Methods**
|
|
236
|
-
- [isBanglaYear](#isbanglayear)
|
|
237
|
-
- [isBanglaYearEn](#isbanglayear)
|
|
238
|
-
- [isBanglaMonth](#isbanglamonth)
|
|
239
|
-
- [isBanglaMonthEn](#isbanglamonthen)
|
|
240
|
-
- [isBanglaDate](#isbangladate)
|
|
241
|
-
- [isBanglaDateEn](#isbangladateen)
|
|
242
|
-
- [isBanglaDateString](#isbangladatestring)
|
|
243
|
-
|
|
244
|
-
- **Symbol Methods**
|
|
245
|
-
|
|
246
|
-
- [Symbol.toPrimitive](#symboltoprimitive)
|
|
247
|
-
- [Symbol.toStringTag](#symboltostringtag)
|
|
248
|
-
|
|
249
|
-
---
|
|
250
|
-
|
|
251
|
-
## Properties
|
|
303
|
+
### Properties
|
|
252
304
|
|
|
253
|
-
|
|
305
|
+
#### variant
|
|
254
306
|
|
|
255
307
|
```typescript
|
|
256
308
|
readonly variant: BnCalendarVariant
|
|
@@ -272,7 +324,7 @@ console.log(cal2019.isLeapYear()); // Follows Gregorian rules
|
|
|
272
324
|
console.log(cal1966.isLeapYear()); // Follows Bangla year % 4 === 2 rule
|
|
273
325
|
```
|
|
274
326
|
|
|
275
|
-
|
|
327
|
+
#### year
|
|
276
328
|
|
|
277
329
|
```typescript
|
|
278
330
|
readonly year: Readonly<{
|
|
@@ -293,7 +345,7 @@ const banglaYear: string = bnCal.year.bn; // Type: BanglaYear
|
|
|
293
345
|
const latinYear: number = bnCal.year.en; // Type: number
|
|
294
346
|
```
|
|
295
347
|
|
|
296
|
-
|
|
348
|
+
#### month
|
|
297
349
|
|
|
298
350
|
```typescript
|
|
299
351
|
readonly month: Readonly<{
|
|
@@ -317,7 +369,7 @@ console.log(bnCal.getMonthName('en')); // 'Bhadro'
|
|
|
317
369
|
const monthNumber: number = bnCal.month.en; // Type: NumberRange<1, 12>
|
|
318
370
|
```
|
|
319
371
|
|
|
320
|
-
|
|
372
|
+
#### date
|
|
321
373
|
|
|
322
374
|
```typescript
|
|
323
375
|
readonly date: Readonly<{
|
|
@@ -337,7 +389,7 @@ console.log(bnCal.date.en); // 15 (Latin digits)
|
|
|
337
389
|
const dayNumber: number = bnCal.date.en; // Type: NumberRange<1, 31>
|
|
338
390
|
```
|
|
339
391
|
|
|
340
|
-
|
|
392
|
+
#### gregorian
|
|
341
393
|
|
|
342
394
|
```typescript
|
|
343
395
|
readonly gregorian: Readonly<{
|
|
@@ -364,7 +416,7 @@ const fromGregorian = new BanglaCalendar(new Date(2023, 3, 14)); // April 14, 20
|
|
|
364
416
|
console.log(fromGregorian.toJSON()); // '১৪৩০-০১-০১'
|
|
365
417
|
```
|
|
366
418
|
|
|
367
|
-
|
|
419
|
+
#### weekDay
|
|
368
420
|
|
|
369
421
|
```typescript
|
|
370
422
|
readonly weekDay: Enumerate<7>
|
|
@@ -390,7 +442,7 @@ if (bnCal.weekDay === 0) {
|
|
|
390
442
|
}
|
|
391
443
|
```
|
|
392
444
|
|
|
393
|
-
|
|
445
|
+
#### isoWeekDay
|
|
394
446
|
|
|
395
447
|
```typescript
|
|
396
448
|
readonly isoWeekDay: NumberRange<1, 7>
|
|
@@ -419,67 +471,80 @@ console.log(mondayDate.toJSON()); // Get Monday's date
|
|
|
419
471
|
|
|
420
472
|
---
|
|
421
473
|
|
|
422
|
-
|
|
474
|
+
### Instance Methods
|
|
423
475
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
```typescript
|
|
427
|
-
const today = new BanglaCalendar();
|
|
428
|
-
console.log(today.toString()); // "শুক্রবার, ১ বৈশাখ, ১৪৩০ [গ্রীষ্ম]"
|
|
429
|
-
console.log(today.toJSON()); // "১৪৩০-০১-০১"
|
|
476
|
+
#### format()
|
|
430
477
|
|
|
431
|
-
|
|
432
|
-
console.log(specificDate.getMonthName()); // "ফাল্গুন"
|
|
433
|
-
```
|
|
478
|
+
Formats the current date as a Bangla calendar date string using customizable tokens.
|
|
434
479
|
|
|
435
|
-
|
|
480
|
+
##### Signature
|
|
436
481
|
|
|
437
482
|
```typescript
|
|
438
|
-
|
|
439
|
-
const gregorianDate = bnDate.toDate();
|
|
440
|
-
console.log(gregorianDate.toISOString()); // "2023-04-14T00:00:00.000Z"
|
|
483
|
+
format(format?: BanglaDateFormat): string
|
|
441
484
|
```
|
|
442
485
|
|
|
443
|
-
|
|
486
|
+
##### Parameters
|
|
487
|
+
|
|
488
|
+
- `format`: Format string using tokens (default: `'ddd, DD mmmm (SS), YYYY বঙ্গাব্দ'`)
|
|
489
|
+
|
|
490
|
+
##### Return Value
|
|
491
|
+
|
|
492
|
+
Formatted Bangla date string according to the specified format.
|
|
493
|
+
|
|
494
|
+
##### Examples
|
|
444
495
|
|
|
445
496
|
```typescript
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
497
|
+
const bnCal = new BanglaCalendar('2023-04-14');
|
|
498
|
+
|
|
499
|
+
bnCal.format();
|
|
500
|
+
// Returns: 'শুক্রবার, বৈশাখ ০১ (গ্রীষ্মকাল), ১৪৩০ বঙ্গাব্দ'
|
|
501
|
+
|
|
502
|
+
bnCal.format('YYYY-MM-DD');
|
|
503
|
+
// Returns: '১৪৩০-০১-০১'
|
|
504
|
+
|
|
505
|
+
bnCal.format('mmmm DD, YYYY');
|
|
506
|
+
// Returns: 'বৈশাখ ০১, ১৪৩০'
|
|
449
507
|
```
|
|
450
508
|
|
|
451
|
-
|
|
509
|
+
##### Format Tokens
|
|
452
510
|
|
|
453
|
-
|
|
511
|
+
- **Year**: `YYYY`/`yyyy` (full year), `YY`/`yy` (last 2 digits)
|
|
512
|
+
- **Month**: `M`/`MM` (padded), `mmm` (short name), `mmmm` (full name)
|
|
513
|
+
- **Day**: `D`/`DD` (padded), `Do` (cardinal)
|
|
514
|
+
- **Weekday**: `d` (short), `dd` (without 'বার'), `ddd` (full)
|
|
515
|
+
- **Season**: `S` (season), `SS` (season with 'কাল' suffix)
|
|
454
516
|
|
|
455
|
-
|
|
517
|
+
##### Escaping Text
|
|
456
518
|
|
|
457
|
-
|
|
519
|
+
To output raw text (not interpreted as a token), wrap it in square brackets:
|
|
520
|
+
|
|
521
|
+
- `[আজ] ddd` → `আজ রবিবার`
|
|
522
|
+
- `[year ]YYYY` → `year ২০২৫`
|
|
458
523
|
|
|
459
|
-
|
|
524
|
+
---
|
|
460
525
|
|
|
461
|
-
|
|
526
|
+
#### valueOf()
|
|
462
527
|
|
|
463
528
|
Gets the numeric timestamp (in milliseconds) for the current Bangla date.
|
|
464
529
|
|
|
465
|
-
|
|
530
|
+
##### Signature
|
|
466
531
|
|
|
467
532
|
```typescript
|
|
468
533
|
valueOf(): number
|
|
469
534
|
```
|
|
470
535
|
|
|
471
|
-
|
|
536
|
+
##### Return Value
|
|
472
537
|
|
|
473
538
|
Unix timestamp in milliseconds representing the Gregorian equivalent of the current Bangla date.
|
|
474
539
|
|
|
475
|
-
|
|
540
|
+
##### Example
|
|
476
541
|
|
|
477
542
|
```typescript
|
|
478
543
|
const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
|
|
479
544
|
const timestamp = bnCal.valueOf(); // 1681430400000 (equivalent to April 14, 2023)
|
|
480
545
|
```
|
|
481
546
|
|
|
482
|
-
|
|
547
|
+
##### Remarks
|
|
483
548
|
|
|
484
549
|
- Internally calls [**`toDate().getTime()`**](#todate) to convert the Bangla date to Gregorian and get its timestamp
|
|
485
550
|
- The time component is normalized to midnight UTC during conversion
|
|
@@ -487,81 +552,81 @@ const timestamp = bnCal.valueOf(); // 1681430400000 (equivalent to April 14, 202
|
|
|
487
552
|
|
|
488
553
|
---
|
|
489
554
|
|
|
490
|
-
|
|
555
|
+
#### isLeapYear()
|
|
491
556
|
|
|
492
557
|
Checks if the current Bangla year is a leap year according to the selected calendar variant.
|
|
493
558
|
|
|
494
|
-
|
|
559
|
+
##### Signature
|
|
495
560
|
|
|
496
561
|
```typescript
|
|
497
562
|
isLeapYear(): boolean
|
|
498
563
|
```
|
|
499
564
|
|
|
500
|
-
|
|
565
|
+
##### Return Value
|
|
501
566
|
|
|
502
567
|
`true` if the year is a leap year, `false` otherwise.
|
|
503
568
|
|
|
504
|
-
|
|
569
|
+
##### Example
|
|
505
570
|
|
|
506
571
|
```typescript
|
|
507
572
|
const date = new BanglaCalendar(1430, 1, 1);
|
|
508
573
|
const isLeap = date.isLeapYear(); // false
|
|
509
574
|
```
|
|
510
575
|
|
|
511
|
-
|
|
576
|
+
##### Remarks
|
|
512
577
|
|
|
513
578
|
- **Revised-2019**: Follows Gregorian leap year rules (divisible by 4, not by 100 unless also divisible by 400)
|
|
514
579
|
- **Revised-1966**: Leap year when `bnYear % 4 === 2`
|
|
515
580
|
|
|
516
581
|
---
|
|
517
582
|
|
|
518
|
-
|
|
583
|
+
#### toDate()
|
|
519
584
|
|
|
520
585
|
Converts the Bangla calendar date to a JavaScript Date object.
|
|
521
586
|
|
|
522
|
-
|
|
587
|
+
##### Signature
|
|
523
588
|
|
|
524
589
|
```typescript
|
|
525
590
|
toDate(): Date
|
|
526
591
|
```
|
|
527
592
|
|
|
528
|
-
|
|
593
|
+
##### Return Value
|
|
529
594
|
|
|
530
595
|
Gregorian Date object equivalent to the Bangla date.
|
|
531
596
|
|
|
532
|
-
|
|
597
|
+
##### Example
|
|
533
598
|
|
|
534
599
|
```typescript
|
|
535
600
|
const bnDate = new BanglaCalendar('১৪৩০', '১', '১');
|
|
536
601
|
const gregorianDate = bnDate.toDate(); // Date for April 14, 2023
|
|
537
602
|
```
|
|
538
603
|
|
|
539
|
-
|
|
604
|
+
##### Remarks
|
|
540
605
|
|
|
541
606
|
- Time component is always set to `00:00:00` in UTC
|
|
542
607
|
- Accounts for calendar variant and leap year rules
|
|
543
608
|
|
|
544
609
|
---
|
|
545
610
|
|
|
546
|
-
|
|
611
|
+
#### getSeasonName()
|
|
547
612
|
|
|
548
613
|
Gets the Bangla season name for the current date.
|
|
549
614
|
|
|
550
|
-
|
|
615
|
+
##### Signature
|
|
551
616
|
|
|
552
617
|
```typescript
|
|
553
618
|
getSeasonName<Locale extends $BnEn = 'bn'>(locale?: Locale): BanglaSeasonName<Locale>
|
|
554
619
|
```
|
|
555
620
|
|
|
556
|
-
|
|
621
|
+
##### Parameters
|
|
557
622
|
|
|
558
623
|
- `locale`: Output locale (`'bn'` for Bengali, `'en'` for English). Defaults to `'bn'`.
|
|
559
624
|
|
|
560
|
-
|
|
625
|
+
##### Return Value
|
|
561
626
|
|
|
562
627
|
Name of the season in the specified locale.
|
|
563
628
|
|
|
564
|
-
|
|
629
|
+
##### Example
|
|
565
630
|
|
|
566
631
|
```typescript
|
|
567
632
|
const bnCal = new BanglaCalendar('2023-04-14');
|
|
@@ -569,7 +634,7 @@ bnCal.getSeasonName(); // "গ্রীষ্ম"
|
|
|
569
634
|
bnCal.getSeasonName('en'); // "Grisma (Summer)"
|
|
570
635
|
```
|
|
571
636
|
|
|
572
|
-
|
|
637
|
+
##### Seasons
|
|
573
638
|
|
|
574
639
|
- গ্রীষ্ম (Summer): Mid-April to Mid-June
|
|
575
640
|
- বর্ষা (Monsoon): Mid-June to Mid-August
|
|
@@ -580,25 +645,25 @@ bnCal.getSeasonName('en'); // "Grisma (Summer)"
|
|
|
580
645
|
|
|
581
646
|
---
|
|
582
647
|
|
|
583
|
-
|
|
648
|
+
#### getMonthName()
|
|
584
649
|
|
|
585
650
|
Gets the Bangla name of the month for the current date.
|
|
586
651
|
|
|
587
|
-
|
|
652
|
+
##### Signature
|
|
588
653
|
|
|
589
654
|
```typescript
|
|
590
655
|
getMonthName<Locale extends $BnEn = 'bn'>(locale?: Locale): BanglaMonthName<Locale>
|
|
591
656
|
```
|
|
592
657
|
|
|
593
|
-
|
|
658
|
+
##### Parameters
|
|
594
659
|
|
|
595
660
|
- `locale`: Output locale (`'bn'` for Bengali, `'en'` for English). Defaults to `'bn'`.
|
|
596
661
|
|
|
597
|
-
|
|
662
|
+
##### Return Value
|
|
598
663
|
|
|
599
664
|
Name of the month in the specified locale.
|
|
600
665
|
|
|
601
|
-
|
|
666
|
+
##### Example
|
|
602
667
|
|
|
603
668
|
```typescript
|
|
604
669
|
const bnCal = new BanglaCalendar('2023-04-14');
|
|
@@ -608,25 +673,25 @@ bnCal.getMonthName('en'); // "Boishakh"
|
|
|
608
673
|
|
|
609
674
|
---
|
|
610
675
|
|
|
611
|
-
|
|
676
|
+
#### getDayName()
|
|
612
677
|
|
|
613
678
|
Gets the Bangla name of the weekday for the current date.
|
|
614
679
|
|
|
615
|
-
|
|
680
|
+
##### Signature
|
|
616
681
|
|
|
617
682
|
```typescript
|
|
618
683
|
getDayName<Locale extends $BnEn = 'bn'>(locale?: Locale): BanglaDayName<Locale>
|
|
619
684
|
```
|
|
620
685
|
|
|
621
|
-
|
|
686
|
+
##### Parameters
|
|
622
687
|
|
|
623
688
|
- `locale`: Output locale (`'bn'` for Bengali, `'en'` for English). Defaults to `'bn'`.
|
|
624
689
|
|
|
625
|
-
|
|
690
|
+
##### Return Value
|
|
626
691
|
|
|
627
692
|
Name of the weekday in the specified locale.
|
|
628
693
|
|
|
629
|
-
|
|
694
|
+
##### Example
|
|
630
695
|
|
|
631
696
|
```typescript
|
|
632
697
|
const bnCal = new BanglaCalendar('2023-04-14'); // Friday
|
|
@@ -636,77 +701,77 @@ bnCal.getDayName('en'); // "Shukrobar (Friday)"
|
|
|
636
701
|
|
|
637
702
|
---
|
|
638
703
|
|
|
639
|
-
|
|
704
|
+
#### startOfMonth()
|
|
640
705
|
|
|
641
706
|
Gets a new BanglaCalendar instance representing the first day of the current month.
|
|
642
707
|
|
|
643
|
-
|
|
708
|
+
##### Signature
|
|
644
709
|
|
|
645
710
|
```typescript
|
|
646
711
|
startOfMonth(): BanglaCalendar
|
|
647
712
|
```
|
|
648
713
|
|
|
649
|
-
|
|
714
|
+
##### Return Value
|
|
650
715
|
|
|
651
716
|
A BanglaCalendar instance set to the 1st day of the current month.
|
|
652
717
|
|
|
653
|
-
|
|
718
|
+
##### Example
|
|
654
719
|
|
|
655
720
|
```typescript
|
|
656
721
|
const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
|
|
657
722
|
const startOfMonth = bnCal.startOfMonth(); // ১ জ্যৈষ্ঠ ১৪৩০
|
|
658
723
|
```
|
|
659
724
|
|
|
660
|
-
|
|
725
|
+
##### Remarks
|
|
661
726
|
|
|
662
727
|
- Preserves the calendar variant of the original
|
|
663
728
|
- Time component is set to midnight UTC
|
|
664
729
|
|
|
665
730
|
---
|
|
666
731
|
|
|
667
|
-
|
|
732
|
+
#### endOfMonth()
|
|
668
733
|
|
|
669
734
|
Gets a new `BanglaCalendar` instance representing the last day of the current month.
|
|
670
735
|
|
|
671
|
-
|
|
736
|
+
##### Signature
|
|
672
737
|
|
|
673
738
|
```typescript
|
|
674
739
|
endOfMonth(): BanglaCalendar
|
|
675
740
|
```
|
|
676
741
|
|
|
677
|
-
|
|
742
|
+
##### Return Value
|
|
678
743
|
|
|
679
744
|
A `BanglaCalendar` instance set to the last day of the current month.
|
|
680
745
|
|
|
681
|
-
|
|
746
|
+
##### Example
|
|
682
747
|
|
|
683
748
|
```typescript
|
|
684
749
|
const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
|
|
685
750
|
const endOfMonth = bnCal.endOfMonth(); // ৩১ জ্যৈষ্ঠ ১৪৩০
|
|
686
751
|
```
|
|
687
752
|
|
|
688
|
-
|
|
753
|
+
##### Remarks
|
|
689
754
|
|
|
690
755
|
- Accounts for month length variations (29/30/31 days)
|
|
691
756
|
- Includes leap year adjustments
|
|
692
757
|
|
|
693
758
|
---
|
|
694
759
|
|
|
695
|
-
|
|
760
|
+
#### startOfYear()
|
|
696
761
|
|
|
697
762
|
Gets a new `BanglaCalendar` instance representing the first day of the current year (১ বৈশাখ).
|
|
698
763
|
|
|
699
|
-
|
|
764
|
+
##### Signature
|
|
700
765
|
|
|
701
766
|
```typescript
|
|
702
767
|
startOfYear(): BanglaCalendar
|
|
703
768
|
```
|
|
704
769
|
|
|
705
|
-
|
|
770
|
+
##### Return Value
|
|
706
771
|
|
|
707
772
|
A `BanglaCalendar` instance set to ১ বৈশাখ of the current year.
|
|
708
773
|
|
|
709
|
-
|
|
774
|
+
##### Example
|
|
710
775
|
|
|
711
776
|
```typescript
|
|
712
777
|
const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
|
|
@@ -715,21 +780,21 @@ const startOfYear = bnCal.startOfYear(); // ১ বৈশাখ ১৪৩০
|
|
|
715
780
|
|
|
716
781
|
---
|
|
717
782
|
|
|
718
|
-
|
|
783
|
+
#### endOfYear()
|
|
719
784
|
|
|
720
785
|
Gets a new `BanglaCalendar` instance representing the last day of the current year (৩০ চৈত্র).
|
|
721
786
|
|
|
722
|
-
|
|
787
|
+
##### Signature
|
|
723
788
|
|
|
724
789
|
```typescript
|
|
725
790
|
endOfYear(): BanglaCalendar
|
|
726
791
|
```
|
|
727
792
|
|
|
728
|
-
|
|
793
|
+
##### Return Value
|
|
729
794
|
|
|
730
795
|
A `BanglaCalendar` instance set to ৩০ চৈত্র of the current year.
|
|
731
796
|
|
|
732
|
-
|
|
797
|
+
##### Example
|
|
733
798
|
|
|
734
799
|
```typescript
|
|
735
800
|
const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
|
|
@@ -738,25 +803,25 @@ const endOfYear = bnCal.endOfYear(); // ৩০ চৈত্র ১৪৩০
|
|
|
738
803
|
|
|
739
804
|
---
|
|
740
805
|
|
|
741
|
-
|
|
806
|
+
#### daysInMonth()
|
|
742
807
|
|
|
743
808
|
Gets the number of days in a Bangla month.
|
|
744
809
|
|
|
745
|
-
|
|
810
|
+
##### Signature
|
|
746
811
|
|
|
747
812
|
```typescript
|
|
748
813
|
daysInMonth(month?: NumberRange<1, 12>): NumberRange<29, 31>
|
|
749
814
|
```
|
|
750
815
|
|
|
751
|
-
|
|
816
|
+
##### Parameters
|
|
752
817
|
|
|
753
818
|
- `month`: Optional Bangla month (1-12 in Latin digits). If not provided, uses the current month.
|
|
754
819
|
|
|
755
|
-
|
|
820
|
+
##### Return Value
|
|
756
821
|
|
|
757
822
|
Number of days in the specified month (29, 30, or 31).
|
|
758
823
|
|
|
759
|
-
|
|
824
|
+
##### Example
|
|
760
825
|
|
|
761
826
|
```typescript
|
|
762
827
|
const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
|
|
@@ -766,76 +831,76 @@ bnCal.daysInMonth(12); // 30 (চৈত্র has 30 days)
|
|
|
766
831
|
|
|
767
832
|
---
|
|
768
833
|
|
|
769
|
-
|
|
834
|
+
#### toJSON()
|
|
770
835
|
|
|
771
836
|
Returns a string representation of the Bangla date in ISO-like format (`YYYY-MM-DD` with Bangla digits).
|
|
772
837
|
|
|
773
|
-
|
|
838
|
+
##### Signature
|
|
774
839
|
|
|
775
840
|
```typescript
|
|
776
841
|
toJSON(): string
|
|
777
842
|
```
|
|
778
843
|
|
|
779
|
-
|
|
844
|
+
##### Return Value
|
|
780
845
|
|
|
781
846
|
Bangla date string in the format: `"YYYY-MM-DD"` (e.g., `"১৪৩০-০১-০১"`).
|
|
782
847
|
|
|
783
|
-
|
|
848
|
+
##### Example
|
|
784
849
|
|
|
785
850
|
```typescript
|
|
786
851
|
const bnCal = new BanglaCalendar('2023-04-14');
|
|
787
852
|
console.log(bnCal.toJSON()); // "১৪৩০-০১-০১"
|
|
788
853
|
```
|
|
789
854
|
|
|
790
|
-
|
|
855
|
+
##### Remarks
|
|
791
856
|
|
|
792
857
|
- Automatically called by `JSON.stringify()`
|
|
793
858
|
- Output follows: `"বছর-মাস-দিন"` with zero-padded Bangla digits
|
|
794
859
|
|
|
795
860
|
---
|
|
796
861
|
|
|
797
|
-
|
|
862
|
+
#### toString()
|
|
798
863
|
|
|
799
864
|
Returns a string representation of the Bangla date in Bengali format.
|
|
800
865
|
|
|
801
|
-
|
|
866
|
+
##### Signature
|
|
802
867
|
|
|
803
868
|
```typescript
|
|
804
869
|
toString(): string
|
|
805
870
|
```
|
|
806
871
|
|
|
807
|
-
|
|
872
|
+
##### Return Value
|
|
808
873
|
|
|
809
874
|
Bangla date string in the format: "শুক্রবার, ১৫ জ্যৈষ্ঠ, ১৪৩০ [গ্রীষ্ম]".
|
|
810
875
|
|
|
811
|
-
|
|
876
|
+
##### Example
|
|
812
877
|
|
|
813
878
|
```typescript
|
|
814
879
|
const bnCal = new BanglaCalendar('2023-04-14');
|
|
815
880
|
console.log(bnCal.toString()); // "শুক্রবার, ১ বৈশাখ, ১৪৩০ [গ্রীষ্ম]"
|
|
816
881
|
```
|
|
817
882
|
|
|
818
|
-
|
|
883
|
+
##### Remarks
|
|
819
884
|
|
|
820
885
|
- Equivalent to [toStringEn()](#tostringen) with `'bn'` locale
|
|
821
886
|
|
|
822
887
|
---
|
|
823
888
|
|
|
824
|
-
|
|
889
|
+
#### toStringEn()
|
|
825
890
|
|
|
826
891
|
Returns a string representation of the Bangla date in English/Latin format.
|
|
827
892
|
|
|
828
|
-
|
|
893
|
+
##### Signature
|
|
829
894
|
|
|
830
895
|
```typescript
|
|
831
896
|
toStringEn(): string
|
|
832
897
|
```
|
|
833
898
|
|
|
834
|
-
|
|
899
|
+
##### Return Value
|
|
835
900
|
|
|
836
901
|
Bangla date string in the format: "Shukrobar (Friday), 15 Joishtho, 1430 [Grisma (Summer)]".
|
|
837
902
|
|
|
838
|
-
|
|
903
|
+
##### Example
|
|
839
904
|
|
|
840
905
|
```typescript
|
|
841
906
|
const bnCal = new BanglaCalendar('2023-04-14');
|
|
@@ -844,75 +909,25 @@ console.log(bnCal.toStringEn()); // "Shukrobar (Friday), 1 Boishakh, 1430 [Grism
|
|
|
844
909
|
|
|
845
910
|
---
|
|
846
911
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
Formats the current date as a Bangla calendar date string using customizable tokens.
|
|
850
|
-
|
|
851
|
-
### Signature
|
|
852
|
-
|
|
853
|
-
```typescript
|
|
854
|
-
format(format?: BanglaDateFormat): string
|
|
855
|
-
```
|
|
856
|
-
|
|
857
|
-
### Parameters
|
|
858
|
-
|
|
859
|
-
- `format`: Format string using tokens (default: `'ddd, DD mmmm (SS), YYYY বঙ্গাব্দ'`)
|
|
860
|
-
|
|
861
|
-
### Return Value
|
|
862
|
-
|
|
863
|
-
Formatted Bangla date string according to the specified format.
|
|
864
|
-
|
|
865
|
-
### Examples
|
|
866
|
-
|
|
867
|
-
```typescript
|
|
868
|
-
const bnCal = new BanglaCalendar('2023-04-14');
|
|
869
|
-
|
|
870
|
-
bnCal.format();
|
|
871
|
-
// Returns: 'শুক্রবার, বৈশাখ ০১ (গ্রীষ্মকাল), ১৪৩০ বঙ্গাব্দ'
|
|
872
|
-
|
|
873
|
-
bnCal.format('YYYY-MM-DD');
|
|
874
|
-
// Returns: '১৪৩০-০১-০১'
|
|
875
|
-
|
|
876
|
-
bnCal.format('mmmm DD, YYYY');
|
|
877
|
-
// Returns: 'বৈশাখ ০১, ১৪৩০'
|
|
878
|
-
```
|
|
879
|
-
|
|
880
|
-
### Format Tokens
|
|
881
|
-
|
|
882
|
-
- **Year**: `YYYY`/`yyyy` (full year), `YY`/`yy` (last 2 digits)
|
|
883
|
-
- **Month**: `M`/`MM` (padded), `mmm` (short name), `mmmm` (full name)
|
|
884
|
-
- **Day**: `D`/`DD` (padded), `Do` (cardinal)
|
|
885
|
-
- **Weekday**: `d` (short), `dd` (without 'বার'), `ddd` (full)
|
|
886
|
-
- **Season**: `S` (season), `SS` (season with 'কাল' suffix)
|
|
887
|
-
|
|
888
|
-
### Escaping Text
|
|
889
|
-
|
|
890
|
-
To output raw text (not interpreted as a token), wrap it in square brackets:
|
|
891
|
-
|
|
892
|
-
- `[আজ] ddd` → `আজ রবিবার`
|
|
893
|
-
- `[year ]YYYY` → `year ২০২৫`
|
|
894
|
-
|
|
895
|
-
---
|
|
896
|
-
|
|
897
|
-
## addDays()
|
|
912
|
+
#### addDays()
|
|
898
913
|
|
|
899
914
|
Adds (or subtracts) days to (or from) the current Bangla date.
|
|
900
915
|
|
|
901
|
-
|
|
916
|
+
##### Signature
|
|
902
917
|
|
|
903
918
|
```typescript
|
|
904
919
|
addDays(days: number): BanglaCalendar
|
|
905
920
|
```
|
|
906
921
|
|
|
907
|
-
|
|
922
|
+
##### Parameters
|
|
908
923
|
|
|
909
924
|
- `days`: Number of days to add (negative values subtract days)
|
|
910
925
|
|
|
911
|
-
|
|
926
|
+
##### Return Value
|
|
912
927
|
|
|
913
928
|
A new `BanglaCalendar` instance with the adjusted date.
|
|
914
929
|
|
|
915
|
-
|
|
930
|
+
##### Example
|
|
916
931
|
|
|
917
932
|
```typescript
|
|
918
933
|
const bnCal = new BanglaCalendar('১৪৩০', '১', '১'); // ১ বৈশাখ ১৪৩০
|
|
@@ -929,7 +944,7 @@ const lateDate = new BanglaCalendar('১৪৩০', '১২', '২৫');
|
|
|
929
944
|
lateDate.addDays(10); // ৫ বৈশাখ ১৪৩১
|
|
930
945
|
```
|
|
931
946
|
|
|
932
|
-
|
|
947
|
+
##### Remarks
|
|
933
948
|
|
|
934
949
|
- Preserves the calendar variant of the original instance
|
|
935
950
|
- Handles month and year transitions automatically
|
|
@@ -939,25 +954,25 @@ lateDate.addDays(10); // ৫ বৈশাখ ১৪৩১
|
|
|
939
954
|
|
|
940
955
|
---
|
|
941
956
|
|
|
942
|
-
|
|
957
|
+
#### addWeeks()
|
|
943
958
|
|
|
944
959
|
Adds (or subtracts) weeks to (or from) the current Bangla date.
|
|
945
960
|
|
|
946
|
-
|
|
961
|
+
##### Signature
|
|
947
962
|
|
|
948
963
|
```typescript
|
|
949
964
|
addWeeks(weeks: number): BanglaCalendar
|
|
950
965
|
```
|
|
951
966
|
|
|
952
|
-
|
|
967
|
+
##### Parameters
|
|
953
968
|
|
|
954
969
|
- `weeks`: Number of weeks to add (negative values subtract weeks)
|
|
955
970
|
|
|
956
|
-
|
|
971
|
+
##### Return Value
|
|
957
972
|
|
|
958
973
|
A new `BanglaCalendar` instance with the adjusted date.
|
|
959
974
|
|
|
960
|
-
|
|
975
|
+
##### Example
|
|
961
976
|
|
|
962
977
|
```typescript
|
|
963
978
|
const bnCal = new BanglaCalendar('১৪৩০', '১', '১'); // ১ বৈশাখ ১৪৩০
|
|
@@ -970,7 +985,7 @@ bnCal.addWeeks(5); // ৫ জ্যৈষ্ঠ ১৪৩০
|
|
|
970
985
|
bnCal.addWeeks(-1); // ২৪ চৈত্র ১৪২৯
|
|
971
986
|
```
|
|
972
987
|
|
|
973
|
-
|
|
988
|
+
##### Remarks
|
|
974
989
|
|
|
975
990
|
- Each week is treated as exactly 7 days
|
|
976
991
|
- Preserves the calendar variant of the original instance
|
|
@@ -980,28 +995,28 @@ bnCal.addWeeks(-1); // ২৪ চৈত্র ১৪২৯
|
|
|
980
995
|
|
|
981
996
|
---
|
|
982
997
|
|
|
983
|
-
|
|
998
|
+
#### addMonths()
|
|
984
999
|
|
|
985
1000
|
Adds (or subtracts) months to (or from) the current Bangla date.
|
|
986
1001
|
|
|
987
|
-
|
|
1002
|
+
##### Signature
|
|
988
1003
|
|
|
989
1004
|
```typescript
|
|
990
1005
|
addMonths(months: number, overflow?: boolean): BanglaCalendar
|
|
991
1006
|
```
|
|
992
1007
|
|
|
993
|
-
|
|
1008
|
+
##### Parameters
|
|
994
1009
|
|
|
995
1010
|
- `months`: Number of months to add (negative values subtract months)
|
|
996
1011
|
- `overflow`: Controls behavior when day doesn't exist in target month (default: `true`)
|
|
997
1012
|
- `true`: Invalid dates overflow to the next month
|
|
998
1013
|
- `false`: Clamps to the last valid day of the target month
|
|
999
1014
|
|
|
1000
|
-
|
|
1015
|
+
##### Return Value
|
|
1001
1016
|
|
|
1002
1017
|
A new `BanglaCalendar` instance with the adjusted date.
|
|
1003
1018
|
|
|
1004
|
-
|
|
1019
|
+
##### Example
|
|
1005
1020
|
|
|
1006
1021
|
```typescript
|
|
1007
1022
|
const normal = new BanglaCalendar('১৪৩০', '২', '১৫');
|
|
@@ -1018,7 +1033,7 @@ edgeCase.addMonths(-1); // ১ আশ্বিন ১৪৩০
|
|
|
1018
1033
|
edgeCase.addMonths(-1, false); // ৩১ ভাদ্র ১৪৩০
|
|
1019
1034
|
```
|
|
1020
1035
|
|
|
1021
|
-
|
|
1036
|
+
##### Remarks
|
|
1022
1037
|
|
|
1023
1038
|
- When `overflow=true` (default): Follows JavaScript `Date` behavior where invalid dates overflow
|
|
1024
1039
|
- When `overflow=false`: Clamps to the last valid day of the target month
|
|
@@ -1028,28 +1043,28 @@ edgeCase.addMonths(-1, false); // ৩১ ভাদ্র ১৪৩০
|
|
|
1028
1043
|
|
|
1029
1044
|
---
|
|
1030
1045
|
|
|
1031
|
-
|
|
1046
|
+
#### addYears()
|
|
1032
1047
|
|
|
1033
1048
|
Adds (or subtracts) years to (or from) the current Bangla date.
|
|
1034
1049
|
|
|
1035
|
-
|
|
1050
|
+
##### Signature
|
|
1036
1051
|
|
|
1037
1052
|
```typescript
|
|
1038
1053
|
addYears(years: number, overflow?: boolean): BanglaCalendar
|
|
1039
1054
|
```
|
|
1040
1055
|
|
|
1041
|
-
|
|
1056
|
+
##### Parameters
|
|
1042
1057
|
|
|
1043
1058
|
- `years`: Number of years to add (negative values subtract years)
|
|
1044
1059
|
- `overflow`: Controls behavior for leap year adjustments (default: `true`)
|
|
1045
1060
|
- `true`: Allows date overflow when day doesn't exist in target year
|
|
1046
1061
|
- `false`: Clamps to last valid day of month in non-leap years
|
|
1047
1062
|
|
|
1048
|
-
|
|
1063
|
+
##### Return Value
|
|
1049
1064
|
|
|
1050
1065
|
A new `BanglaCalendar` instance with the adjusted date.
|
|
1051
1066
|
|
|
1052
|
-
|
|
1067
|
+
##### Example
|
|
1053
1068
|
|
|
1054
1069
|
```typescript
|
|
1055
1070
|
const bnCal = new BanglaCalendar('১৪৩০', '১', '১৫'); // ১৫ বৈশাখ ১৪৩০
|
|
@@ -1066,7 +1081,7 @@ const leapDay = new BanglaCalendar('১৪৩১', '১১', '৩০'); // ৩
|
|
|
1066
1081
|
leapDay.addYears(1, false); // ২৯ ফাল্গুন ১৪৩২ (non-leap year has 29 days)
|
|
1067
1082
|
```
|
|
1068
1083
|
|
|
1069
|
-
|
|
1084
|
+
##### Remarks
|
|
1070
1085
|
|
|
1071
1086
|
- Preserves the calendar variant of the original instance
|
|
1072
1087
|
- Negative values subtract years from the current date
|
|
@@ -1076,25 +1091,25 @@ leapDay.addYears(1, false); // ২৯ ফাল্গুন ১৪৩২ (non-le
|
|
|
1076
1091
|
|
|
1077
1092
|
---
|
|
1078
1093
|
|
|
1079
|
-
|
|
1094
|
+
#### $hasVariantConfig()
|
|
1080
1095
|
|
|
1081
1096
|
Checks if a value is a configuration object that contains a valid calendar `variant`.
|
|
1082
1097
|
|
|
1083
|
-
|
|
1098
|
+
##### Signature
|
|
1084
1099
|
|
|
1085
1100
|
```typescript
|
|
1086
1101
|
$hasVariantConfig(value: unknown): value is { variant: BnCalendarVariant }
|
|
1087
1102
|
```
|
|
1088
1103
|
|
|
1089
|
-
|
|
1104
|
+
##### Parameters
|
|
1090
1105
|
|
|
1091
1106
|
- `value`: The value to check
|
|
1092
1107
|
|
|
1093
|
-
|
|
1108
|
+
##### Return Value
|
|
1094
1109
|
|
|
1095
1110
|
`true` if the value contains a valid `variant` property, `false` otherwise.
|
|
1096
1111
|
|
|
1097
|
-
|
|
1112
|
+
##### Example
|
|
1098
1113
|
|
|
1099
1114
|
```typescript
|
|
1100
1115
|
const bnCal = new BanglaCalendar();
|
|
@@ -1109,7 +1124,7 @@ bnCal.$hasVariantConfig({}); // false
|
|
|
1109
1124
|
bnCal.$hasVariantConfig(null); // false
|
|
1110
1125
|
```
|
|
1111
1126
|
|
|
1112
|
-
|
|
1127
|
+
##### Remarks
|
|
1113
1128
|
|
|
1114
1129
|
- This method is used internally by the constructor to extract variant configuration from various parameter positions
|
|
1115
1130
|
- Can be useful for type-checking configuration objects before passing them to the constructor
|
|
@@ -1117,19 +1132,19 @@ bnCal.$hasVariantConfig(null); // false
|
|
|
1117
1132
|
|
|
1118
1133
|
---
|
|
1119
1134
|
|
|
1120
|
-
|
|
1135
|
+
### Static Methods
|
|
1121
1136
|
|
|
1122
|
-
|
|
1137
|
+
#### isBanglaYear()
|
|
1123
1138
|
|
|
1124
1139
|
Checks whether a value is a valid Bangla year in Bangla digits (`০–৯৯৯৯`).
|
|
1125
1140
|
|
|
1126
|
-
|
|
1141
|
+
##### Signature
|
|
1127
1142
|
|
|
1128
1143
|
```typescript
|
|
1129
1144
|
static isBanglaYear(value: unknown): value is BanglaYear
|
|
1130
1145
|
```
|
|
1131
1146
|
|
|
1132
|
-
|
|
1147
|
+
##### Example
|
|
1133
1148
|
|
|
1134
1149
|
```typescript
|
|
1135
1150
|
BanglaCalendar.isBanglaYear('১৪৩০'); // true
|
|
@@ -1139,17 +1154,17 @@ BanglaCalendar.isBanglaYear('1430'); // false (Latin digits)
|
|
|
1139
1154
|
|
|
1140
1155
|
---
|
|
1141
1156
|
|
|
1142
|
-
|
|
1157
|
+
#### isBanglaYearEn()
|
|
1143
1158
|
|
|
1144
1159
|
Checks whether a value is a valid Bangla year in Latin digits (`0–9999`).
|
|
1145
1160
|
|
|
1146
|
-
|
|
1161
|
+
##### Signature
|
|
1147
1162
|
|
|
1148
1163
|
```typescript
|
|
1149
1164
|
static isBanglaYearEn(value: number): boolean
|
|
1150
1165
|
```
|
|
1151
1166
|
|
|
1152
|
-
|
|
1167
|
+
##### Example
|
|
1153
1168
|
|
|
1154
1169
|
```typescript
|
|
1155
1170
|
BanglaCalendar.isBanglaYearEn(1430); // true
|
|
@@ -1159,17 +1174,17 @@ BanglaCalendar.isBanglaYearEn(-1); // false
|
|
|
1159
1174
|
|
|
1160
1175
|
---
|
|
1161
1176
|
|
|
1162
|
-
|
|
1177
|
+
#### isBanglaMonth()
|
|
1163
1178
|
|
|
1164
1179
|
Checks whether a value is a valid Bangla month in Bangla digits (`১–১২`).
|
|
1165
1180
|
|
|
1166
|
-
|
|
1181
|
+
##### Signature
|
|
1167
1182
|
|
|
1168
1183
|
```typescript
|
|
1169
1184
|
static isBanglaMonth(value: unknown): value is BanglaMonth
|
|
1170
1185
|
```
|
|
1171
1186
|
|
|
1172
|
-
|
|
1187
|
+
##### Example
|
|
1173
1188
|
|
|
1174
1189
|
```typescript
|
|
1175
1190
|
BanglaCalendar.isBanglaMonth('১'); // true
|
|
@@ -1179,17 +1194,17 @@ BanglaCalendar.isBanglaMonth('১৩'); // false
|
|
|
1179
1194
|
|
|
1180
1195
|
---
|
|
1181
1196
|
|
|
1182
|
-
|
|
1197
|
+
#### isBanglaMonthEn()
|
|
1183
1198
|
|
|
1184
1199
|
Checks whether a value is a valid Bangla month in Latin digits (`1–12`).
|
|
1185
1200
|
|
|
1186
|
-
|
|
1201
|
+
##### Signature
|
|
1187
1202
|
|
|
1188
1203
|
```typescript
|
|
1189
1204
|
static isBanglaMonthEn(value: unknown): value is NumberRange<1, 12>
|
|
1190
1205
|
```
|
|
1191
1206
|
|
|
1192
|
-
|
|
1207
|
+
##### Example
|
|
1193
1208
|
|
|
1194
1209
|
```typescript
|
|
1195
1210
|
BanglaCalendar.isBanglaMonthEn(1); // true
|
|
@@ -1199,17 +1214,17 @@ BanglaCalendar.isBanglaMonthEn(13); // false
|
|
|
1199
1214
|
|
|
1200
1215
|
---
|
|
1201
1216
|
|
|
1202
|
-
|
|
1217
|
+
#### isBanglaDate()
|
|
1203
1218
|
|
|
1204
1219
|
Checks whether a value is a valid Bangla date of month in Bangla digits (`১–৩১`).
|
|
1205
1220
|
|
|
1206
|
-
|
|
1221
|
+
##### Signature
|
|
1207
1222
|
|
|
1208
1223
|
```typescript
|
|
1209
1224
|
static isBanglaDate(value: unknown): value is BanglaDate
|
|
1210
1225
|
```
|
|
1211
1226
|
|
|
1212
|
-
|
|
1227
|
+
##### Example
|
|
1213
1228
|
|
|
1214
1229
|
```typescript
|
|
1215
1230
|
BanglaCalendar.isBanglaDate('১'); // true
|
|
@@ -1219,17 +1234,17 @@ BanglaCalendar.isBanglaDate('৩২'); // false
|
|
|
1219
1234
|
|
|
1220
1235
|
---
|
|
1221
1236
|
|
|
1222
|
-
|
|
1237
|
+
#### isBanglaDateEn()
|
|
1223
1238
|
|
|
1224
1239
|
Checks whether a value is a valid Bangla date of month in Latin digits (`1–31`).
|
|
1225
1240
|
|
|
1226
|
-
|
|
1241
|
+
##### Signature
|
|
1227
1242
|
|
|
1228
1243
|
```typescript
|
|
1229
1244
|
static isBanglaDateEn(value: unknown): value is NumberRange<1, 31>
|
|
1230
1245
|
```
|
|
1231
1246
|
|
|
1232
|
-
|
|
1247
|
+
##### Example
|
|
1233
1248
|
|
|
1234
1249
|
```typescript
|
|
1235
1250
|
BanglaCalendar.isBanglaDateEn(1); // true
|
|
@@ -1239,17 +1254,17 @@ BanglaCalendar.isBanglaDateEn(32); // false
|
|
|
1239
1254
|
|
|
1240
1255
|
---
|
|
1241
1256
|
|
|
1242
|
-
|
|
1257
|
+
#### isBanglaDateString()
|
|
1243
1258
|
|
|
1244
1259
|
Checks whether a string follows the Bangla date format pattern (`YYYY-MM-DD` with Bangla digits).
|
|
1245
1260
|
|
|
1246
|
-
|
|
1261
|
+
##### Signature
|
|
1247
1262
|
|
|
1248
1263
|
```typescript
|
|
1249
1264
|
static isBanglaDateString(value: unknown): value is string
|
|
1250
1265
|
```
|
|
1251
1266
|
|
|
1252
|
-
|
|
1267
|
+
##### Example
|
|
1253
1268
|
|
|
1254
1269
|
```typescript
|
|
1255
1270
|
BanglaCalendar.isBanglaDateString('১৪৩০-০১-০১'); // true
|
|
@@ -1257,38 +1272,40 @@ BanglaCalendar.isBanglaDateString('1430-01-01'); // false (Latin digits)
|
|
|
1257
1272
|
BanglaCalendar.isBanglaDateString('১৪৩০-১৩-০১'); // false (invalid month)
|
|
1258
1273
|
```
|
|
1259
1274
|
|
|
1260
|
-
|
|
1275
|
+
##### Remarks
|
|
1261
1276
|
|
|
1262
1277
|
- Accepts both zero-padded and non-padded Bangla digits
|
|
1263
1278
|
- Validates year, month, and date components separately
|
|
1264
1279
|
|
|
1265
1280
|
---
|
|
1266
1281
|
|
|
1267
|
-
|
|
1282
|
+
### Symbol Methods
|
|
1283
|
+
|
|
1284
|
+
#### [Symbol.toPrimitive]
|
|
1268
1285
|
|
|
1269
1286
|
Converts the `BanglaCalendar` instance to a primitive value based on the provided hint.
|
|
1270
1287
|
|
|
1271
|
-
|
|
1288
|
+
##### Signature
|
|
1272
1289
|
|
|
1273
1290
|
```typescript
|
|
1274
1291
|
[Symbol.toPrimitive](hint: string): string | number
|
|
1275
1292
|
```
|
|
1276
1293
|
|
|
1277
|
-
|
|
1294
|
+
##### Parameters
|
|
1278
1295
|
|
|
1279
1296
|
- `hint`: The conversion hint - either `'number'` or `'string'` (defaults to `'string'`)
|
|
1280
1297
|
|
|
1281
|
-
|
|
1298
|
+
##### Return Value
|
|
1282
1299
|
|
|
1283
1300
|
- If `hint` is `'number'`: Returns the timestamp (same as [valueOf()](#valueof))
|
|
1284
1301
|
- Otherwise: Returns the ISO-like Bangla date string (same as [toJSON()](#tojson))
|
|
1285
1302
|
|
|
1286
|
-
|
|
1303
|
+
##### Behavior
|
|
1287
1304
|
|
|
1288
1305
|
- **`hint === 'number'`**: Returns numeric timestamp via [valueOf()](#valueof)
|
|
1289
1306
|
- **`hint === 'string'` or any other hint**: Returns formatted string via [toJSON()](#tojson)
|
|
1290
1307
|
|
|
1291
|
-
|
|
1308
|
+
##### Example
|
|
1292
1309
|
|
|
1293
1310
|
```typescript
|
|
1294
1311
|
const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
|
|
@@ -1307,7 +1324,7 @@ bnCal[Symbol.toPrimitive]('string'); // "১৪৩০-০১-০১"
|
|
|
1307
1324
|
bnCal[Symbol.toPrimitive]('default'); // "১৪৩০-০১-০১"
|
|
1308
1325
|
```
|
|
1309
1326
|
|
|
1310
|
-
|
|
1327
|
+
##### Remarks
|
|
1311
1328
|
|
|
1312
1329
|
- This method enables implicit type conversion in JavaScript/TypeScript
|
|
1313
1330
|
- Follows standard JavaScript object-to-primitive conversion protocol
|
|
@@ -1315,21 +1332,21 @@ bnCal[Symbol.toPrimitive]('default'); // "১৪৩০-০১-০১"
|
|
|
1315
1332
|
|
|
1316
1333
|
---
|
|
1317
1334
|
|
|
1318
|
-
|
|
1335
|
+
#### [Symbol.toStringTag]
|
|
1319
1336
|
|
|
1320
1337
|
Provides a string tag used by `Object.prototype.toString()`.
|
|
1321
1338
|
|
|
1322
|
-
|
|
1339
|
+
##### Signature
|
|
1323
1340
|
|
|
1324
1341
|
```typescript
|
|
1325
1342
|
get [Symbol.toStringTag](): string
|
|
1326
1343
|
```
|
|
1327
1344
|
|
|
1328
|
-
|
|
1345
|
+
##### Return Value
|
|
1329
1346
|
|
|
1330
1347
|
ISO-like Bangla date string in the format `"YYYY-MM-DD"` with Bangla digits.
|
|
1331
1348
|
|
|
1332
|
-
|
|
1349
|
+
##### Example
|
|
1333
1350
|
|
|
1334
1351
|
```typescript
|
|
1335
1352
|
const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
|
|
@@ -1350,7 +1367,7 @@ Object.prototype.toString.call(bnCal); // "[object ১৪৩০-০১-০১]"
|
|
|
1350
1367
|
bnCal[Symbol.toStringTag]; // "১৪৩০-০১-০১"
|
|
1351
1368
|
```
|
|
1352
1369
|
|
|
1353
|
-
|
|
1370
|
+
##### Remarks
|
|
1354
1371
|
|
|
1355
1372
|
- Returns the same value as [toJSON()](#tojson) method
|
|
1356
1373
|
- Used by `Object.prototype.toString()` to identify the object type
|
|
@@ -1358,7 +1375,129 @@ bnCal[Symbol.toStringTag]; // "১৪৩০-০১-০১"
|
|
|
1358
1375
|
|
|
1359
1376
|
---
|
|
1360
1377
|
|
|
1361
|
-
##
|
|
1378
|
+
## Detailed Examples
|
|
1379
|
+
|
|
1380
|
+
### Basic Usage
|
|
1381
|
+
|
|
1382
|
+
```typescript
|
|
1383
|
+
const today = new BanglaCalendar();
|
|
1384
|
+
console.log(today.toString()); // "শুক্রবার, ১ বৈশাখ, ১৪৩০ [গ্রীষ্ম]"
|
|
1385
|
+
console.log(today.toJSON()); // "১৪৩০-০১-০১"
|
|
1386
|
+
|
|
1387
|
+
const specificDate = new BanglaCalendar('১৪৩২-১১-০৮');
|
|
1388
|
+
console.log(specificDate.getMonthName()); // "ফাল্গুন"
|
|
1389
|
+
```
|
|
1390
|
+
|
|
1391
|
+
### Date Conversion
|
|
1392
|
+
|
|
1393
|
+
```typescript
|
|
1394
|
+
const bnDate = new BanglaCalendar('১৪৩০', '১', '১');
|
|
1395
|
+
const gregorianDate = bnDate.toDate();
|
|
1396
|
+
console.log(gregorianDate.toISOString()); // "2023-04-14T00:00:00.000Z"
|
|
1397
|
+
```
|
|
1398
|
+
|
|
1399
|
+
### Month Operations
|
|
1400
|
+
|
|
1401
|
+
```typescript
|
|
1402
|
+
const date = new BanglaCalendar('১৪৩০', '৫', '১৫');
|
|
1403
|
+
console.log(date.startOfMonth().toString()); // "১ জ্যৈষ্ঠ ১৪৩০"
|
|
1404
|
+
console.log(date.endOfMonth().toString()); // "৩১ জ্যৈষ্ঠ ১৪৩০"
|
|
1405
|
+
```
|
|
1406
|
+
|
|
1407
|
+
---
|
|
1408
|
+
|
|
1409
|
+
## Aliases
|
|
1410
|
+
|
|
1411
|
+
`BanglaCalendar` can also be imported using **BnCalendar** and **Bongabdo** aliases.
|
|
1412
|
+
|
|
1413
|
+
```typescript
|
|
1414
|
+
import { BnCalendar, Bongabdo } from 'bn-calendar';
|
|
1415
|
+
|
|
1416
|
+
const bnCal = new BnCalendar('১৪৩০', '১', '১');
|
|
1417
|
+
const bongabdoCal = new Bongabdo('১৪৩০', '১', '১');
|
|
1418
|
+
|
|
1419
|
+
// Same as new BanglaCalendar('১৪৩০', '১', '১')
|
|
1420
|
+
```
|
|
1421
|
+
|
|
1422
|
+
---
|
|
1423
|
+
|
|
1424
|
+
## Type Definitions
|
|
1425
|
+
|
|
1426
|
+
### LocaleCode
|
|
1427
|
+
|
|
1428
|
+
```typescript
|
|
1429
|
+
type $BnEn = 'bn' | 'en'
|
|
1430
|
+
```
|
|
1431
|
+
|
|
1432
|
+
Supported locale codes for Bangla calendar output.
|
|
1433
|
+
|
|
1434
|
+
### BanglaYear
|
|
1435
|
+
|
|
1436
|
+
```typescript
|
|
1437
|
+
type BanglaYear = BanglaDigit | `${$BnOnes}${BanglaDigit}` | `${$BnOnes}${BanglaDigit}${BanglaDigit}` | Repeat<BanglaDigit, 4>
|
|
1438
|
+
```
|
|
1439
|
+
|
|
1440
|
+
Bangla year from `০-৯৯৯৯`.
|
|
1441
|
+
|
|
1442
|
+
### BanglaMonth
|
|
1443
|
+
|
|
1444
|
+
```typescript
|
|
1445
|
+
type BanglaMonth = $BnOnes | $BnOnesPadded | '১০' | '১১' | '১২'
|
|
1446
|
+
```
|
|
1447
|
+
|
|
1448
|
+
Bangla month from `১-১২`.
|
|
1449
|
+
|
|
1450
|
+
### BanglaDate
|
|
1451
|
+
|
|
1452
|
+
```typescript
|
|
1453
|
+
type BanglaDate = $BnOnes | $BnOnesPadded | `১${BanglaDigit}` | `২${BanglaDigit}` | '৩০' | '৩১'
|
|
1454
|
+
```
|
|
1455
|
+
|
|
1456
|
+
Bangla date of month from `১-৩১`.
|
|
1457
|
+
|
|
1458
|
+
### BnCalendarVariant
|
|
1459
|
+
|
|
1460
|
+
```typescript
|
|
1461
|
+
type BnCalendarVariant = 'revised-2019' | 'revised-1966'
|
|
1462
|
+
```
|
|
1463
|
+
|
|
1464
|
+
Calendar variant types.
|
|
1465
|
+
|
|
1466
|
+
### BnCalendarConfig
|
|
1467
|
+
|
|
1468
|
+
```typescript
|
|
1469
|
+
interface BnCalendarConfig {
|
|
1470
|
+
variant?: BnCalendarVariant;
|
|
1471
|
+
}
|
|
1472
|
+
```
|
|
1473
|
+
|
|
1474
|
+
Configuration object for Bangla Calendar system.
|
|
1475
|
+
|
|
1476
|
+
### BanglaDateFormat
|
|
1477
|
+
|
|
1478
|
+
```typescript
|
|
1479
|
+
type BanglaDateFormat = LooseLiteral<DateFormatToken | DateWithSeasonToken>
|
|
1480
|
+
```
|
|
1481
|
+
|
|
1482
|
+
Format tokens for Bangla date formatting.
|
|
1483
|
+
|
|
1484
|
+
---
|
|
1485
|
+
|
|
1486
|
+
## Bangla Digit Conversion Utilities
|
|
1487
|
+
|
|
1488
|
+
> Allows you to convert between Bangla (Bengali) digits (`০-৯`) and Latin (Arabic) digits (`0-9`). Internally `BanglaCalendar` class uses these functions to convert between Bangla and Latin digits.
|
|
1489
|
+
|
|
1490
|
+
### Import
|
|
1491
|
+
|
|
1492
|
+
```typescript
|
|
1493
|
+
import { banglaToDigit, digitToBangla } from 'bn-calendar/utils'
|
|
1494
|
+
```
|
|
1495
|
+
|
|
1496
|
+
---
|
|
1497
|
+
|
|
1498
|
+
> [!NOTE]
|
|
1499
|
+
>
|
|
1500
|
+
> `banglaToDigit()` and `digitToBangla()` functions are imported from the [**nhb-toolbox**](https://toolbox.nazmul-nhb.dev/) package.
|
|
1362
1501
|
|
|
1363
1502
|
The digit conversion utilities provide seamless conversion between Bangla (Bengali) digits (`০-৯`) and Latin (Arabic) digits (`0-9`). These functions are essential for applications that need to handle multilingual numeric representations, particularly in Bengali-language interfaces.
|
|
1364
1503
|
|
|
@@ -1508,125 +1647,6 @@ type BnDigitResult<Force extends boolean> = Force extends true ? number : string
|
|
|
1508
1647
|
|
|
1509
1648
|
---
|
|
1510
1649
|
|
|
1511
|
-
### Complete Examples
|
|
1512
|
-
|
|
1513
|
-
#### Example 1: Form Processing
|
|
1514
|
-
|
|
1515
|
-
```typescript
|
|
1516
|
-
// User inputs Bangla digits in a form
|
|
1517
|
-
const userInput = '২৫০০';
|
|
1518
|
-
const numericValue = banglaToDigit(userInput); // 2500
|
|
1519
|
-
|
|
1520
|
-
// Process the number
|
|
1521
|
-
const discounted = numericValue * 0.9; // 2250
|
|
1522
|
-
|
|
1523
|
-
// Display result in Bangla
|
|
1524
|
-
const displayValue = digitToBangla(discounted); // "২২৫০"
|
|
1525
|
-
```
|
|
1526
|
-
|
|
1527
|
-
#### Example 2: Multilingual Price Display
|
|
1528
|
-
|
|
1529
|
-
```typescript
|
|
1530
|
-
function formatPrice(price: number, locale: 'bn' | 'en' = 'en'): string {
|
|
1531
|
-
if (locale === 'bn') {
|
|
1532
|
-
const banglaPrice = digitToBangla(price);
|
|
1533
|
-
return `৳${banglaPrice}`;
|
|
1534
|
-
}
|
|
1535
|
-
return `$${price.toFixed(2)}`;
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
formatPrice(1250, 'bn'); // "৳১২৫০"
|
|
1539
|
-
formatPrice(1250, 'en'); // "$1250.00"
|
|
1540
|
-
```
|
|
1541
|
-
|
|
1542
|
-
#### Example 3: Phone Number Formatting
|
|
1543
|
-
|
|
1544
|
-
```typescript
|
|
1545
|
-
// Standardize phone number input
|
|
1546
|
-
function formatPhoneNumber(phone: string): string {
|
|
1547
|
-
// Convert any Bangla digits to Latin
|
|
1548
|
-
const latinPhone = banglaToDigit(phone, false); // "01712345678"
|
|
1549
|
-
|
|
1550
|
-
// Format with hyphens
|
|
1551
|
-
return `${latinPhone.slice(0, 3)}-${latinPhone.slice(3, 6)}-${latinPhone.slice(6)}`;
|
|
1552
|
-
}
|
|
1553
|
-
|
|
1554
|
-
formatPhoneNumber('০১৭১২৩৪৫৬৭৮'); // "017-123-45678"
|
|
1555
|
-
```
|
|
1556
|
-
|
|
1557
|
-
> [!TIP]
|
|
1558
|
-
> **Best Practices**
|
|
1559
|
-
>
|
|
1560
|
-
> - **Use `banglaToDigit()` with `forceNumber = true`** when you need to perform calculations
|
|
1561
|
-
> - **Use `banglaToDigit()` with `forceNumber = false`** when you need to preserve text formatting
|
|
1562
|
-
> - **Use `digitToBangla()` with `preserveNonDigit = true`** for displaying formatted text
|
|
1563
|
-
> - **Use `digitToBangla()` with `preserveNonDigit = false`** for generating clean numeric strings
|
|
1564
|
-
> - **Always validate input** before conversion to handle edge cases
|
|
1565
|
-
|
|
1566
|
-
---
|
|
1567
|
-
|
|
1568
|
-
## Type Definitions
|
|
1569
|
-
|
|
1570
|
-
### LocaleCode
|
|
1571
|
-
|
|
1572
|
-
```typescript
|
|
1573
|
-
type $BnEn = 'bn' | 'en'
|
|
1574
|
-
```
|
|
1575
|
-
|
|
1576
|
-
Supported locale codes for Bangla calendar output.
|
|
1577
|
-
|
|
1578
|
-
### BanglaYear
|
|
1579
|
-
|
|
1580
|
-
```typescript
|
|
1581
|
-
type BanglaYear = BanglaDigit | `${$BnOnes}${BanglaDigit}` | `${$BnOnes}${BanglaDigit}${BanglaDigit}` | Repeat<BanglaDigit, 4>
|
|
1582
|
-
```
|
|
1583
|
-
|
|
1584
|
-
Bangla year from `০-৯৯৯৯`.
|
|
1585
|
-
|
|
1586
|
-
### BanglaMonth
|
|
1587
|
-
|
|
1588
|
-
```typescript
|
|
1589
|
-
type BanglaMonth = $BnOnes | $BnOnesPadded | '১০' | '১১' | '১২'
|
|
1590
|
-
```
|
|
1591
|
-
|
|
1592
|
-
Bangla month from `১-১২`.
|
|
1593
|
-
|
|
1594
|
-
### BanglaDate
|
|
1595
|
-
|
|
1596
|
-
```typescript
|
|
1597
|
-
type BanglaDate = $BnOnes | $BnOnesPadded | `১${BanglaDigit}` | `২${BanglaDigit}` | '৩০' | '৩১'
|
|
1598
|
-
```
|
|
1599
|
-
|
|
1600
|
-
Bangla date of month from `১-৩১`.
|
|
1601
|
-
|
|
1602
|
-
### BnCalendarVariant
|
|
1603
|
-
|
|
1604
|
-
```typescript
|
|
1605
|
-
type BnCalendarVariant = 'revised-2019' | 'revised-1966'
|
|
1606
|
-
```
|
|
1607
|
-
|
|
1608
|
-
Calendar variant types.
|
|
1609
|
-
|
|
1610
|
-
### BnCalendarConfig
|
|
1611
|
-
|
|
1612
|
-
```typescript
|
|
1613
|
-
interface BnCalendarConfig {
|
|
1614
|
-
variant?: BnCalendarVariant;
|
|
1615
|
-
}
|
|
1616
|
-
```
|
|
1617
|
-
|
|
1618
|
-
Configuration object for Bangla Calendar system.
|
|
1619
|
-
|
|
1620
|
-
### BanglaDateFormat
|
|
1621
|
-
|
|
1622
|
-
```typescript
|
|
1623
|
-
type BanglaDateFormat = LooseLiteral<DateFormatToken | DateWithSeasonToken>
|
|
1624
|
-
```
|
|
1625
|
-
|
|
1626
|
-
Format tokens for Bangla date formatting.
|
|
1627
|
-
|
|
1628
|
-
---
|
|
1629
|
-
|
|
1630
1650
|
## 🔗 Related Packages
|
|
1631
1651
|
|
|
1632
1652
|
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
|