bn-calendar 1.2.6 → 1.2.10
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 +46 -1557
- package/dist/{dist-CL82Iohb.mjs → dist-C5OaVGq-.mjs} +5 -23
- package/dist/{dist-2u-Hm2TM.cjs → dist-DUk8hJtq.cjs} +4 -22
- package/dist/{object-DyVg8BFt-DFzPgPEP.d.cts → index-RyvzOKVa-BA85h5wj.d.cts} +16 -64
- package/dist/{object-DyVg8BFt-DFzPgPEP.d.mts → index-RyvzOKVa-BA85h5wj.d.mts} +16 -64
- package/dist/index.cjs +6 -5
- package/dist/index.d.cts +16 -8
- package/dist/index.d.mts +16 -8
- package/dist/index.mjs +6 -5
- package/dist/{types-BhqpTl07.d.cts → types-CaovKlY-.d.cts} +2 -18
- package/dist/{types-CuBrWmN0.d.mts → types-HdT16D_P.d.mts} +2 -18
- package/dist/types.d.cts +3 -2
- package/dist/types.d.mts +3 -2
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.cts +4 -14
- package/dist/utils.d.mts +4 -14
- package/dist/utils.mjs +1 -1
- package/package.json +21 -14
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
> Comprehensive Bengali calendar system library built for any JavaScript and TypeScript environment.
|
|
4
4
|
|
|
5
|
+
[](https://bncal.nazmul-nhb.dev/)
|
|
6
|
+
|
|
5
7
|
<p>
|
|
6
8
|
<!-- Package Info -->
|
|
7
9
|
<a href="https://www.npmjs.com/package/bn-calendar" aria-label="NPM Downloads">
|
|
@@ -49,18 +51,6 @@
|
|
|
49
51
|
|
|
50
52
|
`bn-calendar` is a comprehensive Bengali calendar system library built for any JavaScript and TypeScript environment. It supports creation, manipulation, and conversion between Bengali and Gregorian calendars with full support for both `'revised-2019'` (default) and `'revised-1966'` variants.
|
|
51
53
|
|
|
52
|
-
## Features
|
|
53
|
-
|
|
54
|
-
- **Bidirectional Conversion**: Seamlessly convert dates between Gregorian and Bengali calendar systems.
|
|
55
|
-
- **Multiple Variants**: Full support for both `'revised-2019'` (official Bangladesh calendar) and `'revised-1966'` leap year rules.
|
|
56
|
-
- **Rich API**: Extensive methods for date manipulation, formatting, and calculations.
|
|
57
|
-
- **Universal Utilities**: Handy functions to handle conversion between Bangla (`০-৯`) and Latin (`0-9`) digits.
|
|
58
|
-
- **Lightweight & Fast**: Zero dependencies, fully tree-shakable, and optimized for performance.
|
|
59
|
-
- **Universal Compatibility**: Works seamlessly in Node.js, browsers, and any JS/TS environment.
|
|
60
|
-
- **Type-Safe**: Written in TypeScript with comprehensive type definitions.
|
|
61
|
-
|
|
62
|
-
---
|
|
63
|
-
|
|
64
54
|
## Install
|
|
65
55
|
|
|
66
56
|
### NPM
|
|
@@ -89,73 +79,6 @@ yarn add bn-calendar
|
|
|
89
79
|
import { BanglaCalendar } from 'bn-calendar';
|
|
90
80
|
```
|
|
91
81
|
|
|
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)
|
|
156
|
-
|
|
157
|
-
---
|
|
158
|
-
|
|
159
82
|
## Quick Examples
|
|
160
83
|
|
|
161
84
|
**`BanglaCalendar`** - The class to create, manipulate, and convert dates between the Bangla and Gregorian calendar systems.
|
|
@@ -163,1497 +86,69 @@ import { BanglaCalendar } from 'bn-calendar';
|
|
|
163
86
|
> It supports two calendar variants: `'revised-2019'` (default) and `'revised-1966'`.
|
|
164
87
|
|
|
165
88
|
```typescript
|
|
166
|
-
|
|
89
|
+
import { BanglaCalendar } from 'bn-calendar';
|
|
90
|
+
|
|
91
|
+
// 1. Current date in Bangla calendar
|
|
167
92
|
const today = new BanglaCalendar();
|
|
93
|
+
console.log(today.toString());
|
|
94
|
+
// Output: "শুক্রবার, ৯ ফাল্গুন, ১৪৩২ [বসন্ত]"
|
|
168
95
|
|
|
169
|
-
//
|
|
170
|
-
const
|
|
96
|
+
// 2. From Gregorian date string
|
|
97
|
+
const date1 = new BanglaCalendar('2023-04-14');
|
|
98
|
+
console.log(date1.toJSON());
|
|
99
|
+
// Output: "১৪৩০-০১-০১"
|
|
171
100
|
|
|
172
|
-
//
|
|
173
|
-
const
|
|
174
|
-
|
|
101
|
+
// 3. From JavaScript Date object
|
|
102
|
+
const date2 = new BanglaCalendar(new Date(2023, 3, 14));
|
|
103
|
+
console.log(date2.getMonthName());
|
|
104
|
+
// Output: "বৈশাখ"
|
|
175
105
|
|
|
176
|
-
//
|
|
106
|
+
// 4. From specific Bangla components (Year, Month, Date)
|
|
177
107
|
const date3 = new BanglaCalendar(1430, 1, 1);
|
|
108
|
+
console.log(date3.toDate());
|
|
109
|
+
// Output: Fri Apr 14 2023 00:00:00 GMT+0000
|
|
178
110
|
|
|
179
|
-
//
|
|
111
|
+
// 5. Using Bangla digits directly
|
|
180
112
|
const date4 = new BanglaCalendar('১৪৩০', '১', '১');
|
|
181
|
-
|
|
182
|
-
//
|
|
183
|
-
const date5 = new BanglaCalendar('১৪৩০', '১', '১', { variant: 'revised-1966' });
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
---
|
|
187
|
-
|
|
188
|
-
## API Reference
|
|
189
|
-
|
|
190
|
-
### Constructor
|
|
191
|
-
|
|
192
|
-
Creates a new `BanglaCalendar` instance from various input formats.
|
|
193
|
-
|
|
194
|
-
#### Constructor Signatures
|
|
195
|
-
|
|
196
|
-
**Signature 1:** From current date with optional configuration
|
|
197
|
-
|
|
198
|
-
```typescript
|
|
199
|
-
constructor(config?: BnCalendarConfig)
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
**Signature 2:** From Bangla or Gregorian date string
|
|
203
|
-
|
|
204
|
-
```typescript
|
|
205
|
-
constructor(date: string, config?: BnCalendarConfig)
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
**Signature 3:** From Date object
|
|
209
|
-
|
|
210
|
-
```typescript
|
|
211
|
-
constructor(date: Date, config?: BnCalendarConfig)
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
**Signature 4:** From timestamp or Bangla year (Latin digits)
|
|
215
|
-
|
|
216
|
-
```typescript
|
|
217
|
-
constructor(tsOrBnYear: number, config?: BnCalendarConfig)
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
**Signature 5:** From Bangla year (Bangla digits)
|
|
221
|
-
|
|
222
|
-
```typescript
|
|
223
|
-
constructor(bnYear: BanglaYear, config?: BnCalendarConfig)
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
**Signature 6:** From Bangla year and month (Latin digits)
|
|
227
|
-
|
|
228
|
-
```typescript
|
|
229
|
-
constructor(bnYear: number, bnMonth: NumberRange<1, 12>, config?: BnCalendarConfig)
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
**Signature 7:** From Bangla year and month (Bangla digits)
|
|
233
|
-
|
|
234
|
-
```typescript
|
|
235
|
-
constructor(bnYear: BanglaYear, bnMonth: BanglaMonth, config?: BnCalendarConfig)
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
**Signature 8:** From Bangla year, month, and day (Latin digits)
|
|
239
|
-
|
|
240
|
-
```typescript
|
|
241
|
-
constructor(
|
|
242
|
-
bnYear: number,
|
|
243
|
-
bnMonth: NumberRange<1, 12>,
|
|
244
|
-
bnDate: NumberRange<1, 31>,
|
|
245
|
-
config?: BnCalendarConfig
|
|
246
|
-
)
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
**Signature 9:** From Bangla year, month, and day (Bangla digits)
|
|
250
|
-
|
|
251
|
-
```typescript
|
|
252
|
-
constructor(
|
|
253
|
-
bnYear: BanglaYear,
|
|
254
|
-
bnMonth: BanglaMonth,
|
|
255
|
-
bnDate: BanglaDate,
|
|
256
|
-
config?: BnCalendarConfig
|
|
257
|
-
)
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
#### Parameters
|
|
261
|
-
|
|
262
|
-
- `date`: Various date formats including Bangla date strings, Gregorian date strings, Date objects, timestamps, or individual date components
|
|
263
|
-
- `bnYear`: Bengali year in either Bangla (`০-৯৯৯৯`) or Latin (`0-9999`) digits
|
|
264
|
-
- `bnMonth`: Bengali month (1-12 or `১-১২`)
|
|
265
|
-
- `bnDate`: Bengali day of month (1-31 or `১-৩১`)
|
|
266
|
-
- `config`: Optional configuration object with `variant` property (`'revised-2019'` or `'revised-1966'`)
|
|
267
|
-
|
|
268
|
-
#### Behavior
|
|
269
|
-
|
|
270
|
-
- Automatically detects input format and parses accordingly
|
|
271
|
-
- Defaults to current date if no valid input is provided
|
|
272
|
-
- Uses `'revised-2019'` variant by default
|
|
273
|
-
- Validates all date components
|
|
274
|
-
- Handles leap years according to the selected variant
|
|
275
|
-
|
|
276
|
-
#### Examples
|
|
277
|
-
|
|
278
|
-
```typescript
|
|
279
|
-
// Current date
|
|
280
|
-
new BanglaCalendar();
|
|
281
|
-
|
|
282
|
-
// From Bangla date string
|
|
283
|
-
new BanglaCalendar('১৪৩২-১১-০৮');
|
|
284
|
-
|
|
285
|
-
// From Gregorian date string
|
|
286
|
-
new BanglaCalendar('2023-04-14');
|
|
287
|
-
|
|
288
|
-
// From Date object
|
|
289
|
-
new BanglaCalendar(new Date('2023-04-14'));
|
|
290
|
-
|
|
291
|
-
// From Bangla year, month, date (Latin)
|
|
292
|
-
new BanglaCalendar(1430, 1, 1);
|
|
293
|
-
|
|
294
|
-
// From Bangla year, month, date (Bangla)
|
|
295
|
-
new BanglaCalendar('১৪৩০', '১', '১');
|
|
296
|
-
|
|
297
|
-
// With specific variant
|
|
298
|
-
new BanglaCalendar('১৪৩০', '১', '১', { variant: 'revised-1966' });
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
---
|
|
302
|
-
|
|
303
|
-
### Properties
|
|
304
|
-
|
|
305
|
-
#### variant
|
|
306
|
-
|
|
307
|
-
```typescript
|
|
308
|
-
readonly variant: BnCalendarVariant
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
The calendar variant being used (`'revised-2019'` or `'revised-1966'`).
|
|
312
|
-
|
|
313
|
-
**Example:**
|
|
314
|
-
|
|
315
|
-
```typescript
|
|
316
|
-
const cal2019 = new BanglaCalendar(); // Default: 'revised-2019'
|
|
317
|
-
console.log(cal2019.variant); // 'revised-2019'
|
|
318
|
-
|
|
319
|
-
const cal1966 = new BanglaCalendar({ variant: 'revised-1966' });
|
|
320
|
-
console.log(cal1966.variant); // 'revised-1966'
|
|
321
|
-
|
|
322
|
-
// Different leap year behavior
|
|
323
|
-
console.log(cal2019.isLeapYear()); // Follows Gregorian rules
|
|
324
|
-
console.log(cal1966.isLeapYear()); // Follows Bangla year % 4 === 2 rule
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
#### year
|
|
328
|
-
|
|
329
|
-
```typescript
|
|
330
|
-
readonly year: Readonly<{
|
|
331
|
-
bn: BanglaYear; // Bangla year in Bangla digits
|
|
332
|
-
en: number; // Bangla year in Latin digits
|
|
333
|
-
}>
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
**Example:**
|
|
337
|
-
|
|
338
|
-
```typescript
|
|
339
|
-
const bnCal = new BanglaCalendar('১৪৩০-০১-০১');
|
|
340
|
-
console.log(bnCal.year.bn); // '১৪৩০' (Bangla digits)
|
|
341
|
-
console.log(bnCal.year.en); // 1430 (Latin digits)
|
|
342
|
-
|
|
343
|
-
// Type-safe access
|
|
344
|
-
const banglaYear: string = bnCal.year.bn; // Type: BanglaYear
|
|
345
|
-
const latinYear: number = bnCal.year.en; // Type: number
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
#### month
|
|
349
|
-
|
|
350
|
-
```typescript
|
|
351
|
-
readonly month: Readonly<{
|
|
352
|
-
bn: BanglaMonth; // Bangla month in Bangla digits (১-১২)
|
|
353
|
-
en: NumberRange<1, 12>; // Bangla month in Latin digits (1-12)
|
|
354
|
-
}>
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
**Example:**
|
|
358
|
-
|
|
359
|
-
```typescript
|
|
360
|
-
const bnCal = new BanglaCalendar('১৪৩০-০৫-১৫'); // ভাদ্র ১৫
|
|
361
|
-
console.log(bnCal.month.bn); // '৫' (Bangla digits)
|
|
362
|
-
console.log(bnCal.month.en); // 5 (Latin digits, 1-based)
|
|
363
|
-
|
|
364
|
-
// Get month name to verify
|
|
365
|
-
console.log(bnCal.getMonthName()); // 'ভাদ্র'
|
|
366
|
-
console.log(bnCal.getMonthName('en')); // 'Bhadro'
|
|
367
|
-
|
|
368
|
-
// Type-safe access
|
|
369
|
-
const monthNumber: number = bnCal.month.en; // Type: NumberRange<1, 12>
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
#### date
|
|
373
|
-
|
|
374
|
-
```typescript
|
|
375
|
-
readonly date: Readonly<{
|
|
376
|
-
bn: BanglaDate; // Bangla day of month in Bangla digits (১-৩১)
|
|
377
|
-
en: NumberRange<1, 31>; // Bangla day of month in Latin digits (1-31)
|
|
378
|
-
}>
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
**Example:**
|
|
382
|
-
|
|
383
|
-
```typescript
|
|
384
|
-
const bnCal = new BanglaCalendar('১৪৩০-০৫-১৫'); // ১৫ ভাদ্র
|
|
385
|
-
console.log(bnCal.date.bn); // '১৫' (Bangla digits)
|
|
386
|
-
console.log(bnCal.date.en); // 15 (Latin digits)
|
|
387
|
-
|
|
388
|
-
// Type-safe access
|
|
389
|
-
const dayNumber: number = bnCal.date.en; // Type: NumberRange<1, 31>
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
#### gregorian
|
|
393
|
-
|
|
394
|
-
```typescript
|
|
395
|
-
readonly gregorian: Readonly<{
|
|
396
|
-
year: number; // Gregorian year
|
|
397
|
-
month: NumberRange<1, 12>; // Gregorian month (1-12)
|
|
398
|
-
date: NumberRange<1, 31>; // Gregorian day of month (1-31)
|
|
399
|
-
}>
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
**Example:**
|
|
403
|
-
|
|
404
|
-
```typescript
|
|
405
|
-
const bnCal = new BanglaCalendar('১৪৩০-০১-০১'); // ১ বৈশাখ ১৪৩০
|
|
406
|
-
console.log(bnCal.gregorian.year); // 2023
|
|
407
|
-
console.log(bnCal.gregorian.month); // 4 (April)
|
|
408
|
-
console.log(bnCal.gregorian.date); // 14
|
|
409
|
-
|
|
410
|
-
// Verify conversion
|
|
411
|
-
const gregorianDate = bnCal.toDate();
|
|
412
|
-
console.log(gregorianDate); // Date: Fri Apr 14 2023 00:00:00 GMT+0000
|
|
413
|
-
|
|
414
|
-
// Conversion works both ways
|
|
415
|
-
const fromGregorian = new BanglaCalendar(new Date(2023, 3, 14)); // April 14, 2023
|
|
416
|
-
console.log(fromGregorian.toJSON()); // '১৪৩০-০১-০১'
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
#### weekDay
|
|
420
|
-
|
|
421
|
-
```typescript
|
|
422
|
-
readonly weekDay: Enumerate<7>
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
Day of the week (0-6, where 0 is Sunday/রবিবার).
|
|
426
|
-
|
|
427
|
-
**Example:**
|
|
428
|
-
|
|
429
|
-
```typescript
|
|
430
|
-
const bnCal = new BanglaCalendar('১৪৩০-০১-০১'); // Friday, April 14, 2023
|
|
431
|
-
console.log(bnCal.weekDay); // 5 (Friday)
|
|
432
|
-
|
|
433
|
-
// Get day name to verify
|
|
434
|
-
console.log(bnCal.getDayName()); // 'শুক্রবার'
|
|
435
|
-
console.log(bnCal.getDayName('en')); // 'Shukrobar (Friday)'
|
|
436
|
-
|
|
437
|
-
// Check specific days
|
|
438
|
-
if (bnCal.weekDay === 0) {
|
|
439
|
-
console.log('It is Sunday (রবিবার)');
|
|
440
|
-
} else if (bnCal.weekDay === 5) {
|
|
441
|
-
console.log('It is Friday (শুক্রবার)');
|
|
442
|
-
}
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
#### isoWeekDay
|
|
446
|
-
|
|
447
|
-
```typescript
|
|
448
|
-
readonly isoWeekDay: NumberRange<1, 7>
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
ISO weekday (1 = Monday, 7 = Sunday).
|
|
452
|
-
|
|
453
|
-
**Example:**
|
|
454
|
-
|
|
455
|
-
```typescript
|
|
456
|
-
const bnCal = new BanglaCalendar('১৪৩০-০১-০১'); // Friday, April 14, 2023
|
|
457
|
-
console.log(bnCal.isoWeekDay); // 5 (Friday in ISO format)
|
|
458
|
-
|
|
459
|
-
// Compare with weekDay
|
|
460
|
-
console.log(bnCal.weekDay); // 5 (0-based, Sunday=0)
|
|
461
|
-
console.log(bnCal.isoWeekDay); // 5 (1-based, Monday=1)
|
|
462
|
-
|
|
463
|
-
// Useful for ISO-compliant calculations
|
|
464
|
-
const isWeekend = bnCal.isoWeekDay >= 6; // Saturday or Sunday
|
|
465
|
-
console.log(isWeekend); // false (Friday is not weekend)
|
|
466
|
-
|
|
467
|
-
// ISO week starts on Monday
|
|
468
|
-
const mondayDate = bnCal.addDays(1 - bnCal.isoWeekDay); // Get Monday of the week
|
|
469
|
-
console.log(mondayDate.toJSON()); // Get Monday's date
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
---
|
|
473
|
-
|
|
474
|
-
### Instance Methods
|
|
475
|
-
|
|
476
|
-
#### format()
|
|
477
|
-
|
|
478
|
-
Formats the current date as a Bangla calendar date string using customizable tokens.
|
|
479
|
-
|
|
480
|
-
##### Signature
|
|
481
|
-
|
|
482
|
-
```typescript
|
|
483
|
-
format(format?: BanglaDateFormat): string
|
|
484
|
-
```
|
|
485
|
-
|
|
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
|
|
495
|
-
|
|
496
|
-
```typescript
|
|
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: 'বৈশাখ ০১, ১৪৩০'
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
##### Format Tokens
|
|
510
|
-
|
|
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)
|
|
516
|
-
|
|
517
|
-
##### Escaping Text
|
|
518
|
-
|
|
519
|
-
To output raw text (not interpreted as a token), wrap it in square brackets:
|
|
520
|
-
|
|
521
|
-
- `[আজ] ddd` → `আজ রবিবার`
|
|
522
|
-
- `[year ]YYYY` → `year ২০২৫`
|
|
523
|
-
|
|
524
|
-
---
|
|
525
|
-
|
|
526
|
-
#### valueOf()
|
|
527
|
-
|
|
528
|
-
Gets the numeric timestamp (in milliseconds) for the current Bangla date.
|
|
529
|
-
|
|
530
|
-
##### Signature
|
|
531
|
-
|
|
532
|
-
```typescript
|
|
533
|
-
valueOf(): number
|
|
534
|
-
```
|
|
535
|
-
|
|
536
|
-
##### Return Value
|
|
537
|
-
|
|
538
|
-
Unix timestamp in milliseconds representing the Gregorian equivalent of the current Bangla date.
|
|
539
|
-
|
|
540
|
-
##### Example
|
|
541
|
-
|
|
542
|
-
```typescript
|
|
543
|
-
const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
|
|
544
|
-
const timestamp = bnCal.valueOf(); // 1681430400000 (equivalent to April 14, 2023)
|
|
113
|
+
console.log(date4.toStringEn());
|
|
114
|
+
// Output: "Shukrobar (Friday), 1 Boishakh, 1430 [Grisma (Summer)]"
|
|
545
115
|
```
|
|
546
116
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
- Internally calls [**`toDate().getTime()`**](#todate) to convert the Bangla date to Gregorian and get its timestamp
|
|
550
|
-
- The time component is normalized to midnight UTC during conversion
|
|
551
|
-
- This method is automatically called when the instance is used in numeric contexts
|
|
552
|
-
|
|
553
|
-
---
|
|
554
|
-
|
|
555
|
-
#### isLeapYear()
|
|
556
|
-
|
|
557
|
-
Checks if the current Bangla year is a leap year according to the selected calendar variant.
|
|
558
|
-
|
|
559
|
-
##### Signature
|
|
560
|
-
|
|
561
|
-
```typescript
|
|
562
|
-
isLeapYear(): boolean
|
|
563
|
-
```
|
|
564
|
-
|
|
565
|
-
##### Return Value
|
|
566
|
-
|
|
567
|
-
`true` if the year is a leap year, `false` otherwise.
|
|
568
|
-
|
|
569
|
-
##### Example
|
|
570
|
-
|
|
571
|
-
```typescript
|
|
572
|
-
const date = new BanglaCalendar(1430, 1, 1);
|
|
573
|
-
const isLeap = date.isLeapYear(); // false
|
|
574
|
-
```
|
|
575
|
-
|
|
576
|
-
##### Remarks
|
|
577
|
-
|
|
578
|
-
- **Revised-2019**: Follows Gregorian leap year rules (divisible by 4, not by 100 unless also divisible by 400)
|
|
579
|
-
- **Revised-1966**: Leap year when `bnYear % 4 === 2`
|
|
117
|
+
> Read full documentation: [bncal.nazmul-nhb.dev](https:///bncal.nazmul-nhb.dev/)
|
|
580
118
|
|
|
581
119
|
---
|
|
582
120
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
Converts the Bangla calendar date to a JavaScript Date object.
|
|
586
|
-
|
|
587
|
-
##### Signature
|
|
588
|
-
|
|
589
|
-
```typescript
|
|
590
|
-
toDate(): Date
|
|
591
|
-
```
|
|
592
|
-
|
|
593
|
-
##### Return Value
|
|
594
|
-
|
|
595
|
-
Gregorian Date object equivalent to the Bangla date.
|
|
596
|
-
|
|
597
|
-
##### Example
|
|
598
|
-
|
|
599
|
-
```typescript
|
|
600
|
-
const bnDate = new BanglaCalendar('১৪৩০', '১', '১');
|
|
601
|
-
const gregorianDate = bnDate.toDate(); // Date for April 14, 2023
|
|
602
|
-
```
|
|
603
|
-
|
|
604
|
-
##### Remarks
|
|
121
|
+
## Features
|
|
605
122
|
|
|
606
|
-
-
|
|
607
|
-
-
|
|
123
|
+
- **Bidirectional Conversion**: Seamlessly convert dates between Gregorian and Bengali calendar systems.
|
|
124
|
+
- **Multiple Variants**: Full support for both `'revised-2019'` (official Bangladesh calendar) and `'revised-1966'` leap year rules.
|
|
125
|
+
- **Rich API**: Extensive methods for date manipulation, formatting, and calculations.
|
|
126
|
+
- **Universal Utilities**: Handy functions to handle conversion between Bangla (`০-৯`) and Latin (`0-9`) digits.
|
|
127
|
+
- **Lightweight & Fast**: Zero dependencies, fully tree-shakable, and optimized for performance.
|
|
128
|
+
- **Universal Compatibility**: Works seamlessly in Node.js, browsers, and any JS/TS environment.
|
|
129
|
+
- **Type-Safe**: Written in TypeScript with comprehensive type definitions.
|
|
608
130
|
|
|
609
131
|
---
|
|
610
132
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
Gets the Bangla season name for the current date.
|
|
614
|
-
|
|
615
|
-
##### Signature
|
|
616
|
-
|
|
617
|
-
```typescript
|
|
618
|
-
getSeasonName<Locale extends $BnEn = 'bn'>(locale?: Locale): BanglaSeasonName<Locale>
|
|
619
|
-
```
|
|
620
|
-
|
|
621
|
-
##### Parameters
|
|
622
|
-
|
|
623
|
-
- `locale`: Output locale (`'bn'` for Bengali, `'en'` for English). Defaults to `'bn'`.
|
|
624
|
-
|
|
625
|
-
##### Return Value
|
|
626
|
-
|
|
627
|
-
Name of the season in the specified locale.
|
|
628
|
-
|
|
629
|
-
##### Example
|
|
630
|
-
|
|
631
|
-
```typescript
|
|
632
|
-
const bnCal = new BanglaCalendar('2023-04-14');
|
|
633
|
-
bnCal.getSeasonName(); // "গ্রীষ্ম"
|
|
634
|
-
bnCal.getSeasonName('en'); // "Grisma (Summer)"
|
|
635
|
-
```
|
|
636
|
-
|
|
637
|
-
##### Seasons
|
|
133
|
+
## 🔗 Related Packages
|
|
638
134
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
- বসন্ত (Spring): Mid-February to Mid-April
|
|
135
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
|
|
136
|
+
<a target="_blank" href="https://www.npmjs.com/package/toolbox-x">
|
|
137
|
+
<img src="https://img.shields.io/badge/Utility_Library-toolbox--x-blue" alt="toolbox-x" />
|
|
138
|
+
</a>
|
|
139
|
+
</div>
|
|
645
140
|
|
|
646
|
-
|
|
141
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
|
|
142
|
+
<a target="_blank" href="https://www.npmjs.com/package/chronos-date">
|
|
143
|
+
<img src="https://img.shields.io/badge/Date--Time_Library-chronos--date-green" alt="chronos-date" />
|
|
144
|
+
</a>
|
|
145
|
+
</div>
|
|
647
146
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
```typescript
|
|
655
|
-
getMonthName<Locale extends $BnEn = 'bn'>(locale?: Locale): BanglaMonthName<Locale>
|
|
656
|
-
```
|
|
657
|
-
|
|
658
|
-
##### Parameters
|
|
659
|
-
|
|
660
|
-
- `locale`: Output locale (`'bn'` for Bengali, `'en'` for English). Defaults to `'bn'`.
|
|
661
|
-
|
|
662
|
-
##### Return Value
|
|
663
|
-
|
|
664
|
-
Name of the month in the specified locale.
|
|
665
|
-
|
|
666
|
-
##### Example
|
|
667
|
-
|
|
668
|
-
```typescript
|
|
669
|
-
const bnCal = new BanglaCalendar('2023-04-14');
|
|
670
|
-
bnCal.getMonthName(); // "বৈশাখ"
|
|
671
|
-
bnCal.getMonthName('en'); // "Boishakh"
|
|
672
|
-
```
|
|
673
|
-
|
|
674
|
-
---
|
|
675
|
-
|
|
676
|
-
#### getDayName()
|
|
677
|
-
|
|
678
|
-
Gets the Bangla name of the weekday for the current date.
|
|
679
|
-
|
|
680
|
-
##### Signature
|
|
681
|
-
|
|
682
|
-
```typescript
|
|
683
|
-
getDayName<Locale extends $BnEn = 'bn'>(locale?: Locale): BanglaDayName<Locale>
|
|
684
|
-
```
|
|
685
|
-
|
|
686
|
-
##### Parameters
|
|
687
|
-
|
|
688
|
-
- `locale`: Output locale (`'bn'` for Bengali, `'en'` for English). Defaults to `'bn'`.
|
|
689
|
-
|
|
690
|
-
##### Return Value
|
|
691
|
-
|
|
692
|
-
Name of the weekday in the specified locale.
|
|
693
|
-
|
|
694
|
-
##### Example
|
|
695
|
-
|
|
696
|
-
```typescript
|
|
697
|
-
const bnCal = new BanglaCalendar('2023-04-14'); // Friday
|
|
698
|
-
bnCal.getDayName(); // "শুক্রবার"
|
|
699
|
-
bnCal.getDayName('en'); // "Shukrobar (Friday)"
|
|
700
|
-
```
|
|
701
|
-
|
|
702
|
-
---
|
|
703
|
-
|
|
704
|
-
#### startOfMonth()
|
|
705
|
-
|
|
706
|
-
Gets a new BanglaCalendar instance representing the first day of the current month.
|
|
707
|
-
|
|
708
|
-
##### Signature
|
|
709
|
-
|
|
710
|
-
```typescript
|
|
711
|
-
startOfMonth(): BanglaCalendar
|
|
712
|
-
```
|
|
713
|
-
|
|
714
|
-
##### Return Value
|
|
715
|
-
|
|
716
|
-
A BanglaCalendar instance set to the 1st day of the current month.
|
|
717
|
-
|
|
718
|
-
##### Example
|
|
719
|
-
|
|
720
|
-
```typescript
|
|
721
|
-
const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
|
|
722
|
-
const startOfMonth = bnCal.startOfMonth(); // ১ জ্যৈষ্ঠ ১৪৩০
|
|
723
|
-
```
|
|
724
|
-
|
|
725
|
-
##### Remarks
|
|
726
|
-
|
|
727
|
-
- Preserves the calendar variant of the original
|
|
728
|
-
- Time component is set to midnight UTC
|
|
729
|
-
|
|
730
|
-
---
|
|
731
|
-
|
|
732
|
-
#### endOfMonth()
|
|
733
|
-
|
|
734
|
-
Gets a new `BanglaCalendar` instance representing the last day of the current month.
|
|
735
|
-
|
|
736
|
-
##### Signature
|
|
737
|
-
|
|
738
|
-
```typescript
|
|
739
|
-
endOfMonth(): BanglaCalendar
|
|
740
|
-
```
|
|
741
|
-
|
|
742
|
-
##### Return Value
|
|
743
|
-
|
|
744
|
-
A `BanglaCalendar` instance set to the last day of the current month.
|
|
745
|
-
|
|
746
|
-
##### Example
|
|
747
|
-
|
|
748
|
-
```typescript
|
|
749
|
-
const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
|
|
750
|
-
const endOfMonth = bnCal.endOfMonth(); // ৩১ জ্যৈষ্ঠ ১৪৩০
|
|
751
|
-
```
|
|
752
|
-
|
|
753
|
-
##### Remarks
|
|
754
|
-
|
|
755
|
-
- Accounts for month length variations (29/30/31 days)
|
|
756
|
-
- Includes leap year adjustments
|
|
757
|
-
|
|
758
|
-
---
|
|
759
|
-
|
|
760
|
-
#### startOfYear()
|
|
761
|
-
|
|
762
|
-
Gets a new `BanglaCalendar` instance representing the first day of the current year (১ বৈশাখ).
|
|
763
|
-
|
|
764
|
-
##### Signature
|
|
765
|
-
|
|
766
|
-
```typescript
|
|
767
|
-
startOfYear(): BanglaCalendar
|
|
768
|
-
```
|
|
769
|
-
|
|
770
|
-
##### Return Value
|
|
771
|
-
|
|
772
|
-
A `BanglaCalendar` instance set to ১ বৈশাখ of the current year.
|
|
773
|
-
|
|
774
|
-
##### Example
|
|
775
|
-
|
|
776
|
-
```typescript
|
|
777
|
-
const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
|
|
778
|
-
const startOfYear = bnCal.startOfYear(); // ১ বৈশাখ ১৪৩০
|
|
779
|
-
```
|
|
780
|
-
|
|
781
|
-
---
|
|
782
|
-
|
|
783
|
-
#### endOfYear()
|
|
784
|
-
|
|
785
|
-
Gets a new `BanglaCalendar` instance representing the last day of the current year (৩০ চৈত্র).
|
|
786
|
-
|
|
787
|
-
##### Signature
|
|
788
|
-
|
|
789
|
-
```typescript
|
|
790
|
-
endOfYear(): BanglaCalendar
|
|
791
|
-
```
|
|
792
|
-
|
|
793
|
-
##### Return Value
|
|
794
|
-
|
|
795
|
-
A `BanglaCalendar` instance set to ৩০ চৈত্র of the current year.
|
|
796
|
-
|
|
797
|
-
##### Example
|
|
798
|
-
|
|
799
|
-
```typescript
|
|
800
|
-
const bnCal = new BanglaCalendar('১৪৩০', '৫', '১৫');
|
|
801
|
-
const endOfYear = bnCal.endOfYear(); // ৩০ চৈত্র ১৪৩০
|
|
802
|
-
```
|
|
803
|
-
|
|
804
|
-
---
|
|
805
|
-
|
|
806
|
-
#### daysInMonth()
|
|
807
|
-
|
|
808
|
-
Gets the number of days in a Bangla month.
|
|
809
|
-
|
|
810
|
-
##### Signature
|
|
811
|
-
|
|
812
|
-
```typescript
|
|
813
|
-
daysInMonth(month?: NumberRange<1, 12>): NumberRange<29, 31>
|
|
814
|
-
```
|
|
815
|
-
|
|
816
|
-
##### Parameters
|
|
817
|
-
|
|
818
|
-
- `month`: Optional Bangla month (1-12 in Latin digits). If not provided, uses the current month.
|
|
819
|
-
|
|
820
|
-
##### Return Value
|
|
821
|
-
|
|
822
|
-
Number of days in the specified month (29, 30, or 31).
|
|
823
|
-
|
|
824
|
-
##### Example
|
|
825
|
-
|
|
826
|
-
```typescript
|
|
827
|
-
const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
|
|
828
|
-
bnCal.daysInMonth(); // 31 (বৈশাখ has 31 days)
|
|
829
|
-
bnCal.daysInMonth(12); // 30 (চৈত্র has 30 days)
|
|
830
|
-
```
|
|
831
|
-
|
|
832
|
-
---
|
|
833
|
-
|
|
834
|
-
#### toJSON()
|
|
835
|
-
|
|
836
|
-
Returns a string representation of the Bangla date in ISO-like format (`YYYY-MM-DD` with Bangla digits).
|
|
837
|
-
|
|
838
|
-
##### Signature
|
|
839
|
-
|
|
840
|
-
```typescript
|
|
841
|
-
toJSON(): string
|
|
842
|
-
```
|
|
843
|
-
|
|
844
|
-
##### Return Value
|
|
845
|
-
|
|
846
|
-
Bangla date string in the format: `"YYYY-MM-DD"` (e.g., `"১৪৩০-০১-০১"`).
|
|
847
|
-
|
|
848
|
-
##### Example
|
|
849
|
-
|
|
850
|
-
```typescript
|
|
851
|
-
const bnCal = new BanglaCalendar('2023-04-14');
|
|
852
|
-
console.log(bnCal.toJSON()); // "১৪৩০-০১-০১"
|
|
853
|
-
```
|
|
854
|
-
|
|
855
|
-
##### Remarks
|
|
856
|
-
|
|
857
|
-
- Automatically called by `JSON.stringify()`
|
|
858
|
-
- Output follows: `"বছর-মাস-দিন"` with zero-padded Bangla digits
|
|
859
|
-
|
|
860
|
-
---
|
|
861
|
-
|
|
862
|
-
#### toString()
|
|
863
|
-
|
|
864
|
-
Returns a string representation of the Bangla date in Bengali format.
|
|
865
|
-
|
|
866
|
-
##### Signature
|
|
867
|
-
|
|
868
|
-
```typescript
|
|
869
|
-
toString(): string
|
|
870
|
-
```
|
|
871
|
-
|
|
872
|
-
##### Return Value
|
|
873
|
-
|
|
874
|
-
Bangla date string in the format: "শুক্রবার, ১৫ জ্যৈষ্ঠ, ১৪৩০ [গ্রীষ্ম]".
|
|
875
|
-
|
|
876
|
-
##### Example
|
|
877
|
-
|
|
878
|
-
```typescript
|
|
879
|
-
const bnCal = new BanglaCalendar('2023-04-14');
|
|
880
|
-
console.log(bnCal.toString()); // "শুক্রবার, ১ বৈশাখ, ১৪৩০ [গ্রীষ্ম]"
|
|
881
|
-
```
|
|
882
|
-
|
|
883
|
-
##### Remarks
|
|
884
|
-
|
|
885
|
-
- Equivalent to [toStringEn()](#tostringen) with `'bn'` locale
|
|
886
|
-
|
|
887
|
-
---
|
|
888
|
-
|
|
889
|
-
#### toStringEn()
|
|
890
|
-
|
|
891
|
-
Returns a string representation of the Bangla date in English/Latin format.
|
|
892
|
-
|
|
893
|
-
##### Signature
|
|
894
|
-
|
|
895
|
-
```typescript
|
|
896
|
-
toStringEn(): string
|
|
897
|
-
```
|
|
898
|
-
|
|
899
|
-
##### Return Value
|
|
900
|
-
|
|
901
|
-
Bangla date string in the format: "Shukrobar (Friday), 15 Joishtho, 1430 [Grisma (Summer)]".
|
|
902
|
-
|
|
903
|
-
##### Example
|
|
904
|
-
|
|
905
|
-
```typescript
|
|
906
|
-
const bnCal = new BanglaCalendar('2023-04-14');
|
|
907
|
-
console.log(bnCal.toStringEn()); // "Shukrobar (Friday), 1 Boishakh, 1430 [Grisma (Summer)]"
|
|
908
|
-
```
|
|
909
|
-
|
|
910
|
-
---
|
|
911
|
-
|
|
912
|
-
#### addDays()
|
|
913
|
-
|
|
914
|
-
Adds (or subtracts) days to (or from) the current Bangla date.
|
|
915
|
-
|
|
916
|
-
##### Signature
|
|
917
|
-
|
|
918
|
-
```typescript
|
|
919
|
-
addDays(days: number): BanglaCalendar
|
|
920
|
-
```
|
|
921
|
-
|
|
922
|
-
##### Parameters
|
|
923
|
-
|
|
924
|
-
- `days`: Number of days to add (negative values subtract days)
|
|
925
|
-
|
|
926
|
-
##### Return Value
|
|
927
|
-
|
|
928
|
-
A new `BanglaCalendar` instance with the adjusted date.
|
|
929
|
-
|
|
930
|
-
##### Example
|
|
931
|
-
|
|
932
|
-
```typescript
|
|
933
|
-
const bnCal = new BanglaCalendar('১৪৩০', '১', '১'); // ১ বৈশাখ ১৪৩০
|
|
934
|
-
|
|
935
|
-
// Add days
|
|
936
|
-
bnCal.addDays(7); // ৮ বৈশাখ ১৪৩০
|
|
937
|
-
bnCal.addDays(35); // ৫ জ্যৈষ্ঠ ১৪৩০
|
|
938
|
-
|
|
939
|
-
// Subtract days
|
|
940
|
-
bnCal.addDays(-3); // ২৮ চৈত্র ১৪২৯
|
|
941
|
-
|
|
942
|
-
// Cross year boundary
|
|
943
|
-
const lateDate = new BanglaCalendar('১৪৩০', '১২', '২৫');
|
|
944
|
-
lateDate.addDays(10); // ৫ বৈশাখ ১৪৩১
|
|
945
|
-
```
|
|
946
|
-
|
|
947
|
-
##### Remarks
|
|
948
|
-
|
|
949
|
-
- Preserves the calendar variant of the original instance
|
|
950
|
-
- Handles month and year transitions automatically
|
|
951
|
-
- Accounts for varying month lengths and leap years
|
|
952
|
-
- Negative values subtract days from the current date
|
|
953
|
-
- Time component remains at midnight UTC
|
|
954
|
-
|
|
955
|
-
---
|
|
956
|
-
|
|
957
|
-
#### addWeeks()
|
|
958
|
-
|
|
959
|
-
Adds (or subtracts) weeks to (or from) the current Bangla date.
|
|
960
|
-
|
|
961
|
-
##### Signature
|
|
962
|
-
|
|
963
|
-
```typescript
|
|
964
|
-
addWeeks(weeks: number): BanglaCalendar
|
|
965
|
-
```
|
|
966
|
-
|
|
967
|
-
##### Parameters
|
|
968
|
-
|
|
969
|
-
- `weeks`: Number of weeks to add (negative values subtract weeks)
|
|
970
|
-
|
|
971
|
-
##### Return Value
|
|
972
|
-
|
|
973
|
-
A new `BanglaCalendar` instance with the adjusted date.
|
|
974
|
-
|
|
975
|
-
##### Example
|
|
976
|
-
|
|
977
|
-
```typescript
|
|
978
|
-
const bnCal = new BanglaCalendar('১৪৩০', '১', '১'); // ১ বৈশাখ ১৪৩০
|
|
979
|
-
|
|
980
|
-
// Add weeks
|
|
981
|
-
bnCal.addWeeks(2); // ১৫ বৈশাখ ১৪৩০
|
|
982
|
-
bnCal.addWeeks(5); // ৫ জ্যৈষ্ঠ ১৪৩০
|
|
983
|
-
|
|
984
|
-
// Subtract weeks
|
|
985
|
-
bnCal.addWeeks(-1); // ২৪ চৈত্র ১৪২৯
|
|
986
|
-
```
|
|
987
|
-
|
|
988
|
-
##### Remarks
|
|
989
|
-
|
|
990
|
-
- Each week is treated as exactly 7 days
|
|
991
|
-
- Preserves the calendar variant of the original instance
|
|
992
|
-
- Handles month and year transitions automatically
|
|
993
|
-
- Useful for scheduling recurring weekly events
|
|
994
|
-
- Negative values subtract weeks from the current date
|
|
995
|
-
|
|
996
|
-
---
|
|
997
|
-
|
|
998
|
-
#### addMonths()
|
|
999
|
-
|
|
1000
|
-
Adds (or subtracts) months to (or from) the current Bangla date.
|
|
1001
|
-
|
|
1002
|
-
##### Signature
|
|
1003
|
-
|
|
1004
|
-
```typescript
|
|
1005
|
-
addMonths(months: number, overflow?: boolean): BanglaCalendar
|
|
1006
|
-
```
|
|
1007
|
-
|
|
1008
|
-
##### Parameters
|
|
1009
|
-
|
|
1010
|
-
- `months`: Number of months to add (negative values subtract months)
|
|
1011
|
-
- `overflow`: Controls behavior when day doesn't exist in target month (default: `true`)
|
|
1012
|
-
- `true`: Invalid dates overflow to the next month
|
|
1013
|
-
- `false`: Clamps to the last valid day of the target month
|
|
1014
|
-
|
|
1015
|
-
##### Return Value
|
|
1016
|
-
|
|
1017
|
-
A new `BanglaCalendar` instance with the adjusted date.
|
|
1018
|
-
|
|
1019
|
-
##### Example
|
|
1020
|
-
|
|
1021
|
-
```typescript
|
|
1022
|
-
const normal = new BanglaCalendar('১৪৩০', '২', '১৫');
|
|
1023
|
-
normal.addMonths(1); // ১৫ আষাঢ় ১৪৩০
|
|
1024
|
-
normal.addMonths(1, false); // ১৫ আষাঢ় ১৪৩০
|
|
1025
|
-
|
|
1026
|
-
// Edge case: 31st doesn't exist in কার্তিক (30 days)
|
|
1027
|
-
const edgeCase = new BanglaCalendar('১৪৩০', '৬', '৩১'); // ৩১ আশ্বিন ১৪৩০
|
|
1028
|
-
edgeCase.addMonths(1); // ১ অগ্রহায়ণ ১৪৩০ (overflow)
|
|
1029
|
-
edgeCase.addMonths(1, false); // ৩০ কার্তিক ১৪৩০ (clamped)
|
|
1030
|
-
|
|
1031
|
-
// Subtract months
|
|
1032
|
-
edgeCase.addMonths(-1); // ১ আশ্বিন ১৪৩০
|
|
1033
|
-
edgeCase.addMonths(-1, false); // ৩১ ভাদ্র ১৪৩০
|
|
1034
|
-
```
|
|
1035
|
-
|
|
1036
|
-
##### Remarks
|
|
1037
|
-
|
|
1038
|
-
- When `overflow=true` (default): Follows JavaScript `Date` behavior where invalid dates overflow
|
|
1039
|
-
- When `overflow=false`: Clamps to the last valid day of the target month
|
|
1040
|
-
- Preserves the calendar variant of the original instance
|
|
1041
|
-
- Handles year transitions automatically
|
|
1042
|
-
- Negative values subtract months from the current date
|
|
1043
|
-
|
|
1044
|
-
---
|
|
1045
|
-
|
|
1046
|
-
#### addYears()
|
|
1047
|
-
|
|
1048
|
-
Adds (or subtracts) years to (or from) the current Bangla date.
|
|
1049
|
-
|
|
1050
|
-
##### Signature
|
|
1051
|
-
|
|
1052
|
-
```typescript
|
|
1053
|
-
addYears(years: number, overflow?: boolean): BanglaCalendar
|
|
1054
|
-
```
|
|
1055
|
-
|
|
1056
|
-
##### Parameters
|
|
1057
|
-
|
|
1058
|
-
- `years`: Number of years to add (negative values subtract years)
|
|
1059
|
-
- `overflow`: Controls behavior for leap year adjustments (default: `true`)
|
|
1060
|
-
- `true`: Allows date overflow when day doesn't exist in target year
|
|
1061
|
-
- `false`: Clamps to last valid day of month in non-leap years
|
|
1062
|
-
|
|
1063
|
-
##### Return Value
|
|
1064
|
-
|
|
1065
|
-
A new `BanglaCalendar` instance with the adjusted date.
|
|
1066
|
-
|
|
1067
|
-
##### Example
|
|
1068
|
-
|
|
1069
|
-
```typescript
|
|
1070
|
-
const bnCal = new BanglaCalendar('১৪৩০', '১', '১৫'); // ১৫ বৈশাখ ১৪৩০
|
|
1071
|
-
|
|
1072
|
-
// Add years
|
|
1073
|
-
bnCal.addYears(1); // ১৫ বৈশাখ ১৪৩১
|
|
1074
|
-
bnCal.addYears(5); // ১৫ বৈশাখ ১৪৩৫
|
|
1075
|
-
|
|
1076
|
-
// Subtract years
|
|
1077
|
-
bnCal.addYears(-1); // ১৫ বৈশাখ ১৪২৯
|
|
1078
|
-
|
|
1079
|
-
// Leap year adjustment
|
|
1080
|
-
const leapDay = new BanglaCalendar('১৪৩১', '১১', '৩০'); // ৩০ ফাল্গুন ১৪৩১ (leap year)
|
|
1081
|
-
leapDay.addYears(1, false); // ২৯ ফাল্গুন ১৪৩২ (non-leap year has 29 days)
|
|
1082
|
-
```
|
|
1083
|
-
|
|
1084
|
-
##### Remarks
|
|
1085
|
-
|
|
1086
|
-
- Preserves the calendar variant of the original instance
|
|
1087
|
-
- Negative values subtract years from the current date
|
|
1088
|
-
- Year addition follows Bangla calendar years
|
|
1089
|
-
- The month and day generally remain the same unless affected by leap year rules
|
|
1090
|
-
- When `overflow=false`, dates in ফাল্গুন (month 11) are adjusted for leap year differences
|
|
1091
|
-
|
|
1092
|
-
---
|
|
1093
|
-
|
|
1094
|
-
#### $hasVariantConfig()
|
|
1095
|
-
|
|
1096
|
-
Checks if a value is a configuration object that contains a valid calendar `variant`.
|
|
1097
|
-
|
|
1098
|
-
##### Signature
|
|
1099
|
-
|
|
1100
|
-
```typescript
|
|
1101
|
-
$hasVariantConfig(value: unknown): value is { variant: BnCalendarVariant }
|
|
1102
|
-
```
|
|
1103
|
-
|
|
1104
|
-
##### Parameters
|
|
1105
|
-
|
|
1106
|
-
- `value`: The value to check
|
|
1107
|
-
|
|
1108
|
-
##### Return Value
|
|
1109
|
-
|
|
1110
|
-
`true` if the value contains a valid `variant` property, `false` otherwise.
|
|
1111
|
-
|
|
1112
|
-
##### Example
|
|
1113
|
-
|
|
1114
|
-
```typescript
|
|
1115
|
-
const bnCal = new BanglaCalendar();
|
|
1116
|
-
|
|
1117
|
-
// Valid configuration objects
|
|
1118
|
-
bnCal.$hasVariantConfig({ variant: 'revised-2019' }); // true
|
|
1119
|
-
bnCal.$hasVariantConfig({ variant: 'revised-1966' }); // true
|
|
1120
|
-
|
|
1121
|
-
// Invalid configuration objects
|
|
1122
|
-
bnCal.$hasVariantConfig({ variant: 'invalid' }); // false
|
|
1123
|
-
bnCal.$hasVariantConfig({}); // false
|
|
1124
|
-
bnCal.$hasVariantConfig(null); // false
|
|
1125
|
-
```
|
|
1126
|
-
|
|
1127
|
-
##### Remarks
|
|
1128
|
-
|
|
1129
|
-
- This method is used internally by the constructor to extract variant configuration from various parameter positions
|
|
1130
|
-
- Can be useful for type-checking configuration objects before passing them to the constructor
|
|
1131
|
-
- Validates if the object has a `variant` property and it contains one of the 2 supported values: `'revised-2019'` or `'revised-1966'`
|
|
1132
|
-
|
|
1133
|
-
---
|
|
1134
|
-
|
|
1135
|
-
### Static Methods
|
|
1136
|
-
|
|
1137
|
-
#### isBanglaYear()
|
|
1138
|
-
|
|
1139
|
-
Checks whether a value is a valid Bangla year in Bangla digits (`০–৯৯৯৯`).
|
|
1140
|
-
|
|
1141
|
-
##### Signature
|
|
1142
|
-
|
|
1143
|
-
```typescript
|
|
1144
|
-
static isBanglaYear(value: unknown): value is BanglaYear
|
|
1145
|
-
```
|
|
1146
|
-
|
|
1147
|
-
##### Example
|
|
1148
|
-
|
|
1149
|
-
```typescript
|
|
1150
|
-
BanglaCalendar.isBanglaYear('১৪৩০'); // true
|
|
1151
|
-
BanglaCalendar.isBanglaYear('১০০০০'); // false (too many digits)
|
|
1152
|
-
BanglaCalendar.isBanglaYear('1430'); // false (Latin digits)
|
|
1153
|
-
```
|
|
1154
|
-
|
|
1155
|
-
---
|
|
1156
|
-
|
|
1157
|
-
#### isBanglaYearEn()
|
|
1158
|
-
|
|
1159
|
-
Checks whether a value is a valid Bangla year in Latin digits (`0–9999`).
|
|
1160
|
-
|
|
1161
|
-
##### Signature
|
|
1162
|
-
|
|
1163
|
-
```typescript
|
|
1164
|
-
static isBanglaYearEn(value: number): boolean
|
|
1165
|
-
```
|
|
1166
|
-
|
|
1167
|
-
##### Example
|
|
1168
|
-
|
|
1169
|
-
```typescript
|
|
1170
|
-
BanglaCalendar.isBanglaYearEn(1430); // true
|
|
1171
|
-
BanglaCalendar.isBanglaYearEn(10000); // false
|
|
1172
|
-
BanglaCalendar.isBanglaYearEn(-1); // false
|
|
1173
|
-
```
|
|
1174
|
-
|
|
1175
|
-
---
|
|
1176
|
-
|
|
1177
|
-
#### isBanglaMonth()
|
|
1178
|
-
|
|
1179
|
-
Checks whether a value is a valid Bangla month in Bangla digits (`১–১২`).
|
|
1180
|
-
|
|
1181
|
-
##### Signature
|
|
1182
|
-
|
|
1183
|
-
```typescript
|
|
1184
|
-
static isBanglaMonth(value: unknown): value is BanglaMonth
|
|
1185
|
-
```
|
|
1186
|
-
|
|
1187
|
-
##### Example
|
|
1188
|
-
|
|
1189
|
-
```typescript
|
|
1190
|
-
BanglaCalendar.isBanglaMonth('১'); // true
|
|
1191
|
-
BanglaCalendar.isBanglaMonth('১২'); // true
|
|
1192
|
-
BanglaCalendar.isBanglaMonth('১৩'); // false
|
|
1193
|
-
```
|
|
1194
|
-
|
|
1195
|
-
---
|
|
1196
|
-
|
|
1197
|
-
#### isBanglaMonthEn()
|
|
1198
|
-
|
|
1199
|
-
Checks whether a value is a valid Bangla month in Latin digits (`1–12`).
|
|
1200
|
-
|
|
1201
|
-
##### Signature
|
|
1202
|
-
|
|
1203
|
-
```typescript
|
|
1204
|
-
static isBanglaMonthEn(value: unknown): value is NumberRange<1, 12>
|
|
1205
|
-
```
|
|
1206
|
-
|
|
1207
|
-
##### Example
|
|
1208
|
-
|
|
1209
|
-
```typescript
|
|
1210
|
-
BanglaCalendar.isBanglaMonthEn(1); // true
|
|
1211
|
-
BanglaCalendar.isBanglaMonthEn(12); // true
|
|
1212
|
-
BanglaCalendar.isBanglaMonthEn(13); // false
|
|
1213
|
-
```
|
|
1214
|
-
|
|
1215
|
-
---
|
|
1216
|
-
|
|
1217
|
-
#### isBanglaDate()
|
|
1218
|
-
|
|
1219
|
-
Checks whether a value is a valid Bangla date of month in Bangla digits (`১–৩১`).
|
|
1220
|
-
|
|
1221
|
-
##### Signature
|
|
1222
|
-
|
|
1223
|
-
```typescript
|
|
1224
|
-
static isBanglaDate(value: unknown): value is BanglaDate
|
|
1225
|
-
```
|
|
1226
|
-
|
|
1227
|
-
##### Example
|
|
1228
|
-
|
|
1229
|
-
```typescript
|
|
1230
|
-
BanglaCalendar.isBanglaDate('১'); // true
|
|
1231
|
-
BanglaCalendar.isBanglaDate('৩১'); // true
|
|
1232
|
-
BanglaCalendar.isBanglaDate('৩২'); // false
|
|
1233
|
-
```
|
|
1234
|
-
|
|
1235
|
-
---
|
|
1236
|
-
|
|
1237
|
-
#### isBanglaDateEn()
|
|
1238
|
-
|
|
1239
|
-
Checks whether a value is a valid Bangla date of month in Latin digits (`1–31`).
|
|
1240
|
-
|
|
1241
|
-
##### Signature
|
|
1242
|
-
|
|
1243
|
-
```typescript
|
|
1244
|
-
static isBanglaDateEn(value: unknown): value is NumberRange<1, 31>
|
|
1245
|
-
```
|
|
1246
|
-
|
|
1247
|
-
##### Example
|
|
1248
|
-
|
|
1249
|
-
```typescript
|
|
1250
|
-
BanglaCalendar.isBanglaDateEn(1); // true
|
|
1251
|
-
BanglaCalendar.isBanglaDateEn(31); // true
|
|
1252
|
-
BanglaCalendar.isBanglaDateEn(32); // false
|
|
1253
|
-
```
|
|
1254
|
-
|
|
1255
|
-
---
|
|
1256
|
-
|
|
1257
|
-
#### isBanglaDateString()
|
|
1258
|
-
|
|
1259
|
-
Checks whether a string follows the Bangla date format pattern (`YYYY-MM-DD` with Bangla digits).
|
|
1260
|
-
|
|
1261
|
-
##### Signature
|
|
1262
|
-
|
|
1263
|
-
```typescript
|
|
1264
|
-
static isBanglaDateString(value: unknown): value is string
|
|
1265
|
-
```
|
|
1266
|
-
|
|
1267
|
-
##### Example
|
|
1268
|
-
|
|
1269
|
-
```typescript
|
|
1270
|
-
BanglaCalendar.isBanglaDateString('১৪৩০-০১-০১'); // true
|
|
1271
|
-
BanglaCalendar.isBanglaDateString('1430-01-01'); // false (Latin digits)
|
|
1272
|
-
BanglaCalendar.isBanglaDateString('১৪৩০-১৩-০১'); // false (invalid month)
|
|
1273
|
-
```
|
|
1274
|
-
|
|
1275
|
-
##### Remarks
|
|
1276
|
-
|
|
1277
|
-
- Accepts both zero-padded and non-padded Bangla digits
|
|
1278
|
-
- Validates year, month, and date components separately
|
|
1279
|
-
|
|
1280
|
-
---
|
|
1281
|
-
|
|
1282
|
-
### Symbol Methods
|
|
1283
|
-
|
|
1284
|
-
#### [Symbol.toPrimitive]
|
|
1285
|
-
|
|
1286
|
-
Converts the `BanglaCalendar` instance to a primitive value based on the provided hint.
|
|
1287
|
-
|
|
1288
|
-
##### Signature
|
|
1289
|
-
|
|
1290
|
-
```typescript
|
|
1291
|
-
[Symbol.toPrimitive](hint: string): string | number
|
|
1292
|
-
```
|
|
1293
|
-
|
|
1294
|
-
##### Parameters
|
|
1295
|
-
|
|
1296
|
-
- `hint`: The conversion hint - either `'number'` or `'string'` (defaults to `'string'`)
|
|
1297
|
-
|
|
1298
|
-
##### Return Value
|
|
1299
|
-
|
|
1300
|
-
- If `hint` is `'number'`: Returns the timestamp (same as [valueOf()](#valueof))
|
|
1301
|
-
- Otherwise: Returns the ISO-like Bangla date string (same as [toJSON()](#tojson))
|
|
1302
|
-
|
|
1303
|
-
##### Behavior
|
|
1304
|
-
|
|
1305
|
-
- **`hint === 'number'`**: Returns numeric timestamp via [valueOf()](#valueof)
|
|
1306
|
-
- **`hint === 'string'` or any other hint**: Returns formatted string via [toJSON()](#tojson)
|
|
1307
|
-
|
|
1308
|
-
##### Example
|
|
1309
|
-
|
|
1310
|
-
```typescript
|
|
1311
|
-
const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
|
|
1312
|
-
|
|
1313
|
-
// String context (default)
|
|
1314
|
-
String(bnCal); // "১৪৩০-০১-০১"
|
|
1315
|
-
`${bnCal}`; // "১৪৩০-০১-০১"
|
|
1316
|
-
|
|
1317
|
-
// Numeric context
|
|
1318
|
-
+bunCal; // 1681430400000
|
|
1319
|
-
bnCal * 1; // 1681430400000
|
|
1320
|
-
|
|
1321
|
-
// Using explicit hint
|
|
1322
|
-
bnCal[Symbol.toPrimitive]('number'); // 1681430400000
|
|
1323
|
-
bnCal[Symbol.toPrimitive]('string'); // "১৪৩০-০১-০১"
|
|
1324
|
-
bnCal[Symbol.toPrimitive]('default'); // "১৪৩০-০১-০১"
|
|
1325
|
-
```
|
|
1326
|
-
|
|
1327
|
-
##### Remarks
|
|
1328
|
-
|
|
1329
|
-
- This method enables implicit type conversion in JavaScript/TypeScript
|
|
1330
|
-
- Follows standard JavaScript object-to-primitive conversion protocol
|
|
1331
|
-
- Ensures predictable behavior in arithmetic operations and string concatenation
|
|
1332
|
-
|
|
1333
|
-
---
|
|
1334
|
-
|
|
1335
|
-
#### [Symbol.toStringTag]
|
|
1336
|
-
|
|
1337
|
-
Provides a string tag used by `Object.prototype.toString()`.
|
|
1338
|
-
|
|
1339
|
-
##### Signature
|
|
1340
|
-
|
|
1341
|
-
```typescript
|
|
1342
|
-
get [Symbol.toStringTag](): string
|
|
1343
|
-
```
|
|
1344
|
-
|
|
1345
|
-
##### Return Value
|
|
1346
|
-
|
|
1347
|
-
ISO-like Bangla date string in the format `"YYYY-MM-DD"` with Bangla digits.
|
|
1348
|
-
|
|
1349
|
-
##### Example
|
|
1350
|
-
|
|
1351
|
-
```typescript
|
|
1352
|
-
const bnCal = new BanglaCalendar('১৪৩০', '১', '১');
|
|
1353
|
-
|
|
1354
|
-
console.log(bnCal);
|
|
1355
|
-
// BanglaCalendar [১৪৩০-০১-০১] {
|
|
1356
|
-
// variant: 'revised-2019',
|
|
1357
|
-
// year: { bn: '১৪৩০', en: 1430 },
|
|
1358
|
-
// month: { bn: '১', en: 1 },
|
|
1359
|
-
// date: { bn: '১', en: 1 },
|
|
1360
|
-
// gregorian: { year: 2023, month: 4, date: 14 },
|
|
1361
|
-
// weekDay: 5,
|
|
1362
|
-
// isoWeekDay: 5
|
|
1363
|
-
// }
|
|
1364
|
-
|
|
1365
|
-
Object.prototype.toString.call(bnCal); // "[object ১৪৩০-০১-০১]"
|
|
1366
|
-
|
|
1367
|
-
bnCal[Symbol.toStringTag]; // "১৪৩০-০১-০১"
|
|
1368
|
-
```
|
|
1369
|
-
|
|
1370
|
-
##### Remarks
|
|
1371
|
-
|
|
1372
|
-
- Returns the same value as [toJSON()](#tojson) method
|
|
1373
|
-
- Used by `Object.prototype.toString()` to identify the object type
|
|
1374
|
-
- Provides a human-readable representation in debugging contexts
|
|
1375
|
-
|
|
1376
|
-
---
|
|
1377
|
-
|
|
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 [**toolbox-x**](https://toolbox-x.nazmul-nhb.dev/) package.
|
|
1501
|
-
|
|
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.
|
|
1503
|
-
|
|
1504
|
-
### banglaToDigit()
|
|
1505
|
-
|
|
1506
|
-
Converts Bangla digits to Latin digits with flexible output options.
|
|
1507
|
-
|
|
1508
|
-
#### Signature
|
|
1509
|
-
|
|
1510
|
-
```typescript
|
|
1511
|
-
banglaToDigit<Force extends boolean = true>(bnDigit: string, forceNumber?: Force): BnDigitResult<Force>
|
|
1512
|
-
```
|
|
1513
|
-
|
|
1514
|
-
#### Parameters
|
|
1515
|
-
|
|
1516
|
-
- `bnDigit`: A string containing Bangla digits (`০-৯`)
|
|
1517
|
-
- `forceNumber`:
|
|
1518
|
-
- `true` (default): Returns a `number` (strips non-digit characters)
|
|
1519
|
-
- `false`: Returns a `string` (preserves non-digit characters)
|
|
1520
|
-
|
|
1521
|
-
#### Return Value
|
|
1522
|
-
|
|
1523
|
-
- When `forceNumber = true`: `number` (or `0` or `NaN` if no digits found)
|
|
1524
|
-
- When `forceNumber = false`: `string`
|
|
1525
|
-
|
|
1526
|
-
#### Behavior
|
|
1527
|
-
|
|
1528
|
-
| Input | `forceNumber = true` | `forceNumber = false` |
|
|
1529
|
-
| --------------------------- | ---------------------------- | ------------------------------------ |
|
|
1530
|
-
| Contains only Bangla digits | Returns converted number | Returns converted string |
|
|
1531
|
-
| Contains mixed characters | Returns number (digits only) | Returns string with converted digits |
|
|
1532
|
-
| Empty string | Returns `NaN` | Returns empty string |
|
|
1533
|
-
| No digits in string | Returns `0` or `NaN` | Returns the input string |
|
|
1534
|
-
|
|
1535
|
-
#### Examples
|
|
1536
|
-
|
|
1537
|
-
```typescript
|
|
1538
|
-
// Default behavior (forceNumber = true)
|
|
1539
|
-
banglaToDigit('১২৩'); // 123
|
|
1540
|
-
banglaToDigit('৪৫৬৭'); // 4567
|
|
1541
|
-
banglaToDigit('১২৩abc'); // 123 (non-digits stripped)
|
|
1542
|
-
banglaToDigit('abc'); // 0 (no digits)
|
|
1543
|
-
banglaToDigit(''); // NaN
|
|
1544
|
-
|
|
1545
|
-
// Force string output (forceNumber = false)
|
|
1546
|
-
banglaToDigit('১২৩', false); // "123"
|
|
1547
|
-
banglaToDigit('১২৩abc', false); // "123abc" (preserves non-digits)
|
|
1548
|
-
banglaToDigit('৪৫৬৭', false); // "4567"
|
|
1549
|
-
banglaToDigit('abc', false); // "abc" (empty string)
|
|
1550
|
-
banglaToDigit('', false); // "" (empty string)
|
|
1551
|
-
|
|
1552
|
-
// Complex examples
|
|
1553
|
-
banglaToDigit('আমার বয়স ২৫ বছর'); // 25
|
|
1554
|
-
banglaToDigit('ফোন: ০১৭১২৩৪৫৬৭৮', false); // "ফোন: 01712345678"
|
|
1555
|
-
```
|
|
1556
|
-
|
|
1557
|
-
#### Use Cases
|
|
1558
|
-
|
|
1559
|
-
- Parsing numeric input from Bengali users
|
|
1560
|
-
- Converting database values stored in Bangla digits to numbers for calculations
|
|
1561
|
-
- Processing multilingual forms that accept Bangla numbers
|
|
1562
|
-
- Localization utilities for Bengali applications
|
|
1563
|
-
|
|
1564
|
-
---
|
|
1565
|
-
|
|
1566
|
-
### digitToBangla()
|
|
1567
|
-
|
|
1568
|
-
Converts Latin digits to Bangla digits with optional non-digit preservation.
|
|
1569
|
-
|
|
1570
|
-
#### Signature
|
|
1571
|
-
|
|
1572
|
-
```typescript
|
|
1573
|
-
digitToBangla(digit: number | string, preserveNonDigit = true): string
|
|
1574
|
-
```
|
|
1575
|
-
|
|
1576
|
-
#### Parameters
|
|
1577
|
-
|
|
1578
|
-
- `digit`: A number or string containing Latin digits (0-9)
|
|
1579
|
-
- `preserveNonDigit`:
|
|
1580
|
-
- `true` (default): Preserves non-digit characters in output
|
|
1581
|
-
- `false`: Strips non-numeric characters from output
|
|
1582
|
-
|
|
1583
|
-
#### Return Value
|
|
1584
|
-
|
|
1585
|
-
`string` - Converted Bangla digit string (or empty string for invalid input)
|
|
1586
|
-
|
|
1587
|
-
#### Behavior
|
|
1588
|
-
|
|
1589
|
-
| Input | `preserveNonDigit = true` | `preserveNonDigit = false` |
|
|
1590
|
-
| ---------------------------- | --------------------------------- | ------------------------------ |
|
|
1591
|
-
| Number | Returns Bangla digits | Returns Bangla digits |
|
|
1592
|
-
| String with only digits | Returns Bangla digits | Returns Bangla digits |
|
|
1593
|
-
| String with mixed characters | Converts digits, preserves others | Converts digits, strips others |
|
|
1594
|
-
| Empty string | Returns empty string | Returns empty string |
|
|
1595
|
-
| Non-numeric string | Returns original string | Returns empty string |
|
|
1596
|
-
|
|
1597
|
-
#### Examples
|
|
1598
|
-
|
|
1599
|
-
```typescript
|
|
1600
|
-
// Default behavior (preserveNonDigit = true)
|
|
1601
|
-
digitToBangla(123); // "১২৩"
|
|
1602
|
-
digitToBangla(4567); // "৪৫৬৭"
|
|
1603
|
-
digitToBangla('123'); // "১২৩"
|
|
1604
|
-
digitToBangla('12ab34'); // "১২ab৩৪"
|
|
1605
|
-
digitToBangla('abc'); // "abc"
|
|
1606
|
-
digitToBangla(''); // ""
|
|
1607
|
-
|
|
1608
|
-
// Strip non-digits (preserveNonDigit = false)
|
|
1609
|
-
digitToBangla('12ab34', false); // "১২৩৪" (non-digits removed)
|
|
1610
|
-
digitToBangla('abc', false); // "" (no digits)
|
|
1611
|
-
digitToBangla('১২৩', false); // "১২৩" (already Bangla digits)
|
|
1612
|
-
digitToBangla('', false); // ""
|
|
1613
|
-
|
|
1614
|
-
// Complex examples
|
|
1615
|
-
digitToBangla('Phone: 01712345678');
|
|
1616
|
-
// "Phone: ০১৭১২৩৪৫৬৭৮"
|
|
1617
|
-
|
|
1618
|
-
digitToBangla('আমার বয়স 25 বছর');
|
|
1619
|
-
// "আমার বয়স ২৫ বছর"
|
|
1620
|
-
|
|
1621
|
-
digitToBangla('Price: $99.99', false);
|
|
1622
|
-
// "৯৯৯৯" (strips all non-digits)
|
|
1623
|
-
```
|
|
1624
|
-
|
|
1625
|
-
#### Use Cases
|
|
1626
|
-
|
|
1627
|
-
- Displaying numbers in Bengali interfaces
|
|
1628
|
-
- Formatting prices, quantities, and measurements in Bengali
|
|
1629
|
-
- Generating multilingual receipts and invoices
|
|
1630
|
-
- Localizing numeric data for Bengali users
|
|
1631
|
-
|
|
1632
|
-
---
|
|
1633
|
-
|
|
1634
|
-
### Type Definitions
|
|
1635
|
-
|
|
1636
|
-
#### BanglaDigit
|
|
1637
|
-
|
|
1638
|
-
```typescript
|
|
1639
|
-
type BanglaDigit = '০' | '১' | '২' | '৩' | '৪' | '৫' | '৬' | '৭' | '৮' | '৯';
|
|
1640
|
-
```
|
|
1641
|
-
|
|
1642
|
-
#### BnDigitResult
|
|
1643
|
-
|
|
1644
|
-
```typescript
|
|
1645
|
-
type BnDigitResult<Force extends boolean> = Force extends true ? number : string;
|
|
1646
|
-
```
|
|
1647
|
-
|
|
1648
|
-
---
|
|
1649
|
-
|
|
1650
|
-
## 🔗 Related Packages
|
|
1651
|
-
|
|
1652
|
-
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
|
|
1653
|
-
<a target="_blank" href="https://www.npmjs.com/package/nhb-toolbox">
|
|
1654
|
-
<img src="https://img.shields.io/badge/Utility_Library-nhb--toolbox-blue" alt="nhb-toolbox" />
|
|
1655
|
-
</a>
|
|
1656
|
-
</div>
|
|
147
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
|
|
148
|
+
<a target="_blank" href="https://www.npmjs.com/package/locality-idb">
|
|
149
|
+
<img src="https://img.shields.io/badge/IndexedDB_ORM-locality--idb-darkviolet" alt="locality-idb" />
|
|
150
|
+
</a>
|
|
151
|
+
</div>
|
|
1657
152
|
|
|
1658
153
|
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
|
|
1659
154
|
<a target="_blank" href="https://www.npmjs.com/package/nhb-hooks">
|
|
@@ -1661,12 +156,6 @@ type BnDigitResult<Force extends boolean> = Force extends true ? number : string
|
|
|
1661
156
|
</a>
|
|
1662
157
|
</div>
|
|
1663
158
|
|
|
1664
|
-
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
|
|
1665
|
-
<a target="_blank" href="https://www.npmjs.com/package/locality-idb">
|
|
1666
|
-
<img src="https://img.shields.io/badge/IndexedDB_ORM-locality--idb-darkviolet" alt="locality-idb" />
|
|
1667
|
-
</a>
|
|
1668
|
-
</div>
|
|
1669
|
-
|
|
1670
159
|
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
|
|
1671
160
|
<a target="_blank" href="https://www.npmjs.com/package/nhb-scripts">
|
|
1672
161
|
<img src="https://img.shields.io/badge/Development_Scripts-nhb--scripts-red" alt="nhb-scripts" />
|