@coreify/tarikh 1.0.0
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/LICENSE +21 -0
- package/README.md +478 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +155 -0
- package/dist/index.d.ts +155 -0
- package/dist/index.js +1 -0
- package/dist/react.cjs +2 -0
- package/dist/react.d.cts +52 -0
- package/dist/react.d.ts +52 -0
- package/dist/react.js +2 -0
- package/package.json +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Coreify
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
# @coreify/tarikh
|
|
2
|
+
|
|
3
|
+
The Bangladeshi date toolkit for modern apps.
|
|
4
|
+
|
|
5
|
+
Format dates, render Bangla calendar, and handle localization correctly.
|
|
6
|
+
|
|
7
|
+
## Why this exists
|
|
8
|
+
|
|
9
|
+
JavaScript's `Intl.DateTimeFormat` and libraries like Day.js / date-fns don't solve these problems:
|
|
10
|
+
|
|
11
|
+
- **Bangla calendar** — Convert Gregorian dates to Bengali calendar (বৈশাখ, চৈত্র, etc.)
|
|
12
|
+
- **Bangla digits** — Render `৩১ মার্চ ২০২৬` instead of `31 March 2026`
|
|
13
|
+
- **Hybrid formatting** — Mix English and Bangla in a single date string
|
|
14
|
+
- **Weekday and time formatting** — Render weekday, hour, minute, and second output
|
|
15
|
+
- **Natural relative time** — Use `yesterday`, `tomorrow`, `গতকাল`, `আগামীকাল`, etc.
|
|
16
|
+
- **Cultural correctness** — Bangladeshi locale-aware formatting out of the box
|
|
17
|
+
|
|
18
|
+
`@coreify/tarikh` is a zero-dependency, tree-shakeable, SSR-safe toolkit purpose-built for Bangladesh.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @coreify/tarikh
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import {
|
|
30
|
+
formatDate,
|
|
31
|
+
formatBanglaCalendar,
|
|
32
|
+
fromNow,
|
|
33
|
+
toBanglaCalendar
|
|
34
|
+
} from "@coreify/tarikh";
|
|
35
|
+
|
|
36
|
+
formatDate(new Date(), { locale: "bn-BD" });
|
|
37
|
+
// → "৩১ মার্চ ২০২৬"
|
|
38
|
+
|
|
39
|
+
// Structured Bangla calendar conversion
|
|
40
|
+
// `monthIndex` stays numeric; `bn-BD` localizes `day`, `month`, and `year`.
|
|
41
|
+
toBanglaCalendar("2026-03-31");
|
|
42
|
+
// → { day: 17, month: "Chaitra", monthIndex: 12, year: 1432 }
|
|
43
|
+
|
|
44
|
+
toBanglaCalendar("2026-03-31", { locale: "bn-BD" });
|
|
45
|
+
// → { day: "১৭", month: "চৈত্র", monthIndex: 12, year: "১৪৩২" }
|
|
46
|
+
|
|
47
|
+
formatBanglaCalendar("2026-03-31");
|
|
48
|
+
// → "17 Chaitra 1432"
|
|
49
|
+
|
|
50
|
+
formatBanglaCalendar("2026-03-31", { locale: "bn-BD" });
|
|
51
|
+
// → "১৭ই চৈত্র ১৪৩২"
|
|
52
|
+
|
|
53
|
+
formatBanglaCalendar("2026-04-14", { locale: "bn-BD" });
|
|
54
|
+
// → "১লা বৈশাখ ১৪৩৩"
|
|
55
|
+
|
|
56
|
+
formatDate(new Date(2026, 2, 31, 15, 4), {
|
|
57
|
+
weekday: "short",
|
|
58
|
+
hour: "numeric",
|
|
59
|
+
minute: "2-digit"
|
|
60
|
+
});
|
|
61
|
+
// → "Tue, 31 Mar 2026, 15:04"
|
|
62
|
+
|
|
63
|
+
formatDate(new Date(2026, 2, 31, 21, 4, 9), {
|
|
64
|
+
weekday: "long",
|
|
65
|
+
hour: "2-digit",
|
|
66
|
+
minute: "2-digit",
|
|
67
|
+
second: "2-digit",
|
|
68
|
+
hour12: true
|
|
69
|
+
});
|
|
70
|
+
// → "Tuesday, 31 Mar 2026, 09:04:09 PM"
|
|
71
|
+
|
|
72
|
+
fromNow(new Date(Date.now() - 86400000), { numeric: "auto" });
|
|
73
|
+
// → "yesterday"
|
|
74
|
+
|
|
75
|
+
fromNow(new Date(), { numeric: "auto" });
|
|
76
|
+
// → "today"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Features
|
|
80
|
+
|
|
81
|
+
### Date Formatting
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { formatDate } from "@coreify/tarikh";
|
|
85
|
+
|
|
86
|
+
formatDate(new Date());
|
|
87
|
+
// → "31 Mar 2026"
|
|
88
|
+
|
|
89
|
+
formatDate(new Date(), { locale: "bn-BD" });
|
|
90
|
+
// → "৩১ মার্চ ২০২৬"
|
|
91
|
+
|
|
92
|
+
formatDate(new Date(), { month: "long", year: "2-digit" });
|
|
93
|
+
// → "31 March 26"
|
|
94
|
+
|
|
95
|
+
formatDate(new Date(2026, 2, 31, 15, 4, 9), {
|
|
96
|
+
weekday: "long",
|
|
97
|
+
hour: "2-digit",
|
|
98
|
+
minute: "2-digit",
|
|
99
|
+
second: "2-digit",
|
|
100
|
+
hour12: true
|
|
101
|
+
});
|
|
102
|
+
// → "Tuesday, 31 Mar 2026, 03:04:09 PM"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Options:** `locale` (`"en-BD"` | `"bn-BD"`), `month` (`"short"` | `"long"`), `year` (`"numeric"` | `"2-digit"`), `day` (`"numeric"` | `"2-digit"`), `weekday` (`"short"` | `"long"`), `hour` / `minute` / `second` (`"numeric"` | `"2-digit"`), `hour12` (`boolean`)
|
|
106
|
+
|
|
107
|
+
### Token-based Formatting
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { format } from "@coreify/tarikh";
|
|
111
|
+
|
|
112
|
+
format(new Date(), "DD MMM YYYY");
|
|
113
|
+
// → "31 Mar 2026"
|
|
114
|
+
|
|
115
|
+
format(new Date(), "DD MMMM YYYY", { locale: "bn-BD" });
|
|
116
|
+
// → "৩১ মার্চ ২০২৬"
|
|
117
|
+
|
|
118
|
+
format(new Date(), "DD/MM/YYYY");
|
|
119
|
+
// → "31/03/2026"
|
|
120
|
+
|
|
121
|
+
format(new Date(2026, 2, 31, 15, 4, 9), "ddd, D MMM YYYY HH:mm:ss");
|
|
122
|
+
// → "Tue, 31 Mar 2026 15:04:09"
|
|
123
|
+
|
|
124
|
+
format(new Date(2026, 2, 31, 9, 4), "ddd, D MMM YYYY h:mm a", {
|
|
125
|
+
locale: "bn-BD"
|
|
126
|
+
});
|
|
127
|
+
// → "মঙ্গল, ৩১ মার্চ ২০২৬ ৯:০৪ পূর্বাহ্ণ"
|
|
128
|
+
|
|
129
|
+
format(new Date(2026, 2, 31, 21, 4, 9), "dddd, D MMM YYYY hh:mm:ss A");
|
|
130
|
+
// → "Tuesday, 31 Mar 2026 09:04:09 PM"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Tokens:** `dddd`, `ddd`, `DD`, `D`, `MMMM`, `MMM`, `MM`, `M`, `YYYY`, `YY`, `HH`, `H`, `hh`, `h`, `mm`, `m`, `ss`, `s`, `A`, `a`
|
|
134
|
+
|
|
135
|
+
### Bangla Calendar
|
|
136
|
+
|
|
137
|
+
Convert Gregorian dates to the Bengali calendar (Bangladesh Revised Calendar, 1987).
|
|
138
|
+
|
|
139
|
+
- `toBanglaCalendar()` returns a structured object.
|
|
140
|
+
- Default output: English digits + Latin month names (`en-BD`).
|
|
141
|
+
- Locale-aware output: Bangla date words like `১লা`, `২রা`, `৩রা`, `৪ঠা`, `৫ই`, `১৯শে` plus Bangla month names (`bn-BD`).
|
|
142
|
+
- `monthIndex` remains numeric in both cases.
|
|
143
|
+
- `formatBanglaCalendar(..., { locale: "bn-BD", format: "spoken" })` returns spoken day words like `পহেলা`, `দোসরা`, `তেসরা`, `চৌঠা`.
|
|
144
|
+
- `formatBanglaCalendarDay(day, { format: "spoken" })` returns colloquial spoken forms for the first four days: `পহেলা`, `দোসরা`, `তেসরা`, `চৌঠা`.
|
|
145
|
+
- Pass `{ variant: "pohela" }` to keep the standard `পহেলা` spelling explicitly, or `{ variant: "poyla" }` to get `পয়লা` for day 1. The parser also accepts the common `পয়লা` spelling.
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
import {
|
|
149
|
+
formatBanglaCalendar,
|
|
150
|
+
formatBanglaCalendarDay,
|
|
151
|
+
toBanglaCalendar
|
|
152
|
+
} from "@coreify/tarikh";
|
|
153
|
+
|
|
154
|
+
toBanglaCalendar("2026-03-31");
|
|
155
|
+
// → { day: 17, month: "Chaitra", monthIndex: 12, year: 1432 }
|
|
156
|
+
|
|
157
|
+
toBanglaCalendar("2026-03-31", { locale: "bn-BD" });
|
|
158
|
+
// → { day: "১৭", month: "চৈত্র", monthIndex: 12, year: "১৪৩২" }
|
|
159
|
+
|
|
160
|
+
formatBanglaCalendar("2026-03-31");
|
|
161
|
+
// → "17 Chaitra 1432"
|
|
162
|
+
|
|
163
|
+
formatBanglaCalendar("2026-03-31", { locale: "bn-BD" });
|
|
164
|
+
// → "১৭ই চৈত্র ১৪৩২"
|
|
165
|
+
|
|
166
|
+
formatBanglaCalendar("2026-04-14");
|
|
167
|
+
// → "1 Baishakh 1433"
|
|
168
|
+
|
|
169
|
+
formatBanglaCalendar("2026-04-14", { locale: "bn-BD", format: "spoken" });
|
|
170
|
+
// → "পহেলা বৈশাখ ১৪৩৩"
|
|
171
|
+
|
|
172
|
+
formatBanglaCalendar("2026-04-14", {
|
|
173
|
+
locale: "bn-BD",
|
|
174
|
+
format: "spoken",
|
|
175
|
+
variant: "poyla"
|
|
176
|
+
});
|
|
177
|
+
// → "পয়লা বৈশাখ ১৪৩৩"
|
|
178
|
+
|
|
179
|
+
formatBanglaCalendarDay(21);
|
|
180
|
+
// → "২১শে"
|
|
181
|
+
|
|
182
|
+
formatBanglaCalendarDay(1, { format: "spoken" });
|
|
183
|
+
// → "পহেলা"
|
|
184
|
+
|
|
185
|
+
formatBanglaCalendarDay(1, { format: "spoken", variant: "poyla" });
|
|
186
|
+
// → "পয়লা"
|
|
187
|
+
|
|
188
|
+
formatBanglaCalendarDay(1, { format: "spoken", variant: "pohela" });
|
|
189
|
+
// → "পহেলা"
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Hybrid Formatting
|
|
193
|
+
|
|
194
|
+
Mix English and Bangla independently for day, month, and year.
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import { formatHybridDate } from "@coreify/tarikh";
|
|
198
|
+
|
|
199
|
+
formatHybridDate(new Date());
|
|
200
|
+
// → "31 মার্চ 2026"
|
|
201
|
+
|
|
202
|
+
formatHybridDate(new Date(), { digits: "bn", month: "bn", year: "en" });
|
|
203
|
+
// → "৩১ মার্চ 2026"
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Bangla Digits
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import { toBanglaDigits, toEnglishDigits } from "@coreify/tarikh";
|
|
210
|
+
|
|
211
|
+
toBanglaDigits("31 March 2026");
|
|
212
|
+
// → "৩১ March ২০২৬"
|
|
213
|
+
|
|
214
|
+
toEnglishDigits("৩১ মার্চ ২০২৬");
|
|
215
|
+
// → "31 মার্চ 2026"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Relative Time
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
import { fromNow } from "@coreify/tarikh";
|
|
222
|
+
|
|
223
|
+
fromNow(new Date(Date.now() - 86400000));
|
|
224
|
+
// → "1 day ago"
|
|
225
|
+
|
|
226
|
+
fromNow(new Date(Date.now() - 86400000), { locale: "bn-BD" });
|
|
227
|
+
// → "১ দিন আগে"
|
|
228
|
+
|
|
229
|
+
fromNow(new Date(Date.now() + 3600000));
|
|
230
|
+
// → "in 1 hour"
|
|
231
|
+
|
|
232
|
+
fromNow(new Date(Date.now() - 86400000), { numeric: "auto" });
|
|
233
|
+
// → "yesterday"
|
|
234
|
+
|
|
235
|
+
fromNow(new Date(Date.now() + 86400000), {
|
|
236
|
+
locale: "bn-BD",
|
|
237
|
+
numeric: "auto"
|
|
238
|
+
});
|
|
239
|
+
// → "আগামীকাল"
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Parsing
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
import { parseDate } from "@coreify/tarikh";
|
|
246
|
+
|
|
247
|
+
parseDate("৩১ মার্চ ২০২৬");
|
|
248
|
+
// → Date object (March 31, 2026)
|
|
249
|
+
|
|
250
|
+
parseDate("17 Chaitra 1432", { calendar: "bangla" });
|
|
251
|
+
// → Date object (March 31, 2026)
|
|
252
|
+
|
|
253
|
+
// Legacy spellings (Boishakh, Joishtho, Choitro, etc.) are still accepted.
|
|
254
|
+
|
|
255
|
+
parseDate("১৭ চৈত্র ১৪৩২", { calendar: "bangla" });
|
|
256
|
+
// → Date object (March 31, 2026)
|
|
257
|
+
|
|
258
|
+
parseDate("31 March 2026");
|
|
259
|
+
// → Date object (March 31, 2026)
|
|
260
|
+
|
|
261
|
+
parseDate("March 31, 2026");
|
|
262
|
+
// → Date object (March 31, 2026)
|
|
263
|
+
|
|
264
|
+
parseDate("31-Mar-2026");
|
|
265
|
+
// → Date object (March 31, 2026)
|
|
266
|
+
|
|
267
|
+
parseDate("2026/03/31");
|
|
268
|
+
// → Date object (March 31, 2026)
|
|
269
|
+
|
|
270
|
+
parseDate("2026.03.31");
|
|
271
|
+
// → Date object (March 31, 2026)
|
|
272
|
+
|
|
273
|
+
parseDate("2026-03-31T15:30:00Z");
|
|
274
|
+
// → Date object (March 31, 2026, 3:30 PM UTC)
|
|
275
|
+
|
|
276
|
+
// `toDate()` accepts the same Gregorian string forms as `parseDate()`,
|
|
277
|
+
// plus `Date` objects and timestamps.
|
|
278
|
+
// Supported string shapes:
|
|
279
|
+
// - `YYYY-MM-DD`
|
|
280
|
+
// - `YYYY/MM/DD`
|
|
281
|
+
// - `YYYY.MM.DD`
|
|
282
|
+
// - `YYYY-M-D`, `YYYY/M/D`, `YYYY.M.D`
|
|
283
|
+
// - `YYYY-MM-DDTHH:mm[:ss[.fraction]][Z|±HH:mm]`
|
|
284
|
+
// - `DD Month YYYY`
|
|
285
|
+
// - `Month DD, YYYY`
|
|
286
|
+
// - `DD-Month-YYYY`
|
|
287
|
+
// - Bangla calendar strings like `১৭ চৈত্র ১৪৩২`
|
|
288
|
+
// - Common Bangla month aliases like `Boishakh`, `Poush`, `Falgun`, `Asharh`
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Utilities
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
import {
|
|
295
|
+
isToday,
|
|
296
|
+
isYesterday,
|
|
297
|
+
isTomorrow,
|
|
298
|
+
startOfDay,
|
|
299
|
+
endOfDay,
|
|
300
|
+
startOfMonth,
|
|
301
|
+
endOfMonth,
|
|
302
|
+
startOfYear,
|
|
303
|
+
endOfYear,
|
|
304
|
+
addDays,
|
|
305
|
+
subDays,
|
|
306
|
+
addMonths,
|
|
307
|
+
subMonths,
|
|
308
|
+
addYears,
|
|
309
|
+
subYears,
|
|
310
|
+
getBanglaMonth
|
|
311
|
+
} from "@coreify/tarikh";
|
|
312
|
+
|
|
313
|
+
isToday(new Date()); // → true
|
|
314
|
+
isYesterday(subDays(new Date(), 1)); // → true
|
|
315
|
+
isTomorrow(addDays(new Date(), 1)); // → true
|
|
316
|
+
startOfMonth(new Date()); // → Date at the start of this month
|
|
317
|
+
endOfMonth(new Date()); // → Date at the end of this month
|
|
318
|
+
addMonths("2026-01-31", 1); // → 2026-02-28
|
|
319
|
+
addYears(new Date(2024, 1, 29), 1); // → 2025-02-28
|
|
320
|
+
|
|
321
|
+
getBanglaMonth(3); // → "মার্চ"
|
|
322
|
+
getBanglaMonth(3, "short"); // → "মার্চ"
|
|
323
|
+
getBanglaMonth(12); // → "ডিসেম্বর"
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### Constants
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
import {
|
|
330
|
+
BANGLA_MONTHS_FULL,
|
|
331
|
+
BANGLA_MONTHS_SHORT,
|
|
332
|
+
BANGLA_CALENDAR_MONTHS,
|
|
333
|
+
BANGLA_CALENDAR_MONTHS_EN,
|
|
334
|
+
BANGLA_WEEKDAYS_FULL,
|
|
335
|
+
BANGLA_WEEKDAYS_SHORT,
|
|
336
|
+
ENGLISH_WEEKDAYS_FULL,
|
|
337
|
+
ENGLISH_WEEKDAYS_SHORT,
|
|
338
|
+
BANGLA_DIGITS,
|
|
339
|
+
ENGLISH_DIGITS
|
|
340
|
+
} from "@coreify/tarikh";
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## React Components
|
|
344
|
+
|
|
345
|
+
Optional entry point — only included if you import from `@coreify/tarikh/react`.
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
npm install @coreify/tarikh react
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### Tarikh
|
|
352
|
+
|
|
353
|
+
```tsx
|
|
354
|
+
import { Tarikh } from "@coreify/tarikh/react";
|
|
355
|
+
|
|
356
|
+
<Tarikh value={new Date()} />
|
|
357
|
+
// → <time>31 Mar 2026</time>
|
|
358
|
+
|
|
359
|
+
<Tarikh value={new Date()} locale="bn-BD" />
|
|
360
|
+
// → <time>৩১ মার্চ ২০২৬</time>
|
|
361
|
+
|
|
362
|
+
<Tarikh value={new Date()} month="long" />
|
|
363
|
+
// → <time>31 March 2026</time>
|
|
364
|
+
|
|
365
|
+
<Tarikh
|
|
366
|
+
value={new Date(2026, 2, 31, 15, 4)}
|
|
367
|
+
weekday="short"
|
|
368
|
+
hour="numeric"
|
|
369
|
+
minute="2-digit"
|
|
370
|
+
/>
|
|
371
|
+
// → <time>Tue, 31 Mar 2026, 15:04</time>
|
|
372
|
+
|
|
373
|
+
<Tarikh
|
|
374
|
+
value={new Date(2026, 2, 31, 15, 4, 9)}
|
|
375
|
+
weekday="long"
|
|
376
|
+
hour="2-digit"
|
|
377
|
+
minute="2-digit"
|
|
378
|
+
second="2-digit"
|
|
379
|
+
hour12
|
|
380
|
+
locale="bn-BD"
|
|
381
|
+
/>
|
|
382
|
+
// → <time>মঙ্গলবার, ৩১ মার্চ ২০২৬, ০৩:০৪:০৯ অপরাহ্ণ</time>
|
|
383
|
+
|
|
384
|
+
<Tarikh value="31 March 2026" />
|
|
385
|
+
// → <time dateTime="2026-03-31">31 Mar 2026</time>
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### RelativeTime
|
|
389
|
+
|
|
390
|
+
```tsx
|
|
391
|
+
import { RelativeTime } from "@coreify/tarikh/react";
|
|
392
|
+
|
|
393
|
+
<RelativeTime value={someDate} />
|
|
394
|
+
// → <time>2 days ago</time>
|
|
395
|
+
|
|
396
|
+
<RelativeTime value={someDate} locale="bn-BD" />
|
|
397
|
+
// → <time>২ দিন আগে</time>
|
|
398
|
+
|
|
399
|
+
<RelativeTime value={someDate} numeric="auto" />
|
|
400
|
+
// → <time>yesterday</time> (for a 1-day past date)
|
|
401
|
+
|
|
402
|
+
<RelativeTime value={someDate} locale="bn-BD" numeric="auto" />
|
|
403
|
+
// → <time>আগামীকাল</time> (for a 1-day future date)
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### BanglaDate
|
|
407
|
+
|
|
408
|
+
```tsx
|
|
409
|
+
import { BanglaDate } from "@coreify/tarikh/react";
|
|
410
|
+
|
|
411
|
+
<BanglaDate value={new Date()} />
|
|
412
|
+
// → <time>17 Chaitra 1432</time> (example; depends on date)
|
|
413
|
+
|
|
414
|
+
<BanglaDate value={new Date()} locale="bn-BD" />
|
|
415
|
+
// → <time>১৭ই চৈত্র ১৪৩২</time> (example; depends on date)
|
|
416
|
+
|
|
417
|
+
<BanglaDate
|
|
418
|
+
value={new Date()}
|
|
419
|
+
locale="bn-BD"
|
|
420
|
+
format="spoken"
|
|
421
|
+
variant="poyla"
|
|
422
|
+
/>
|
|
423
|
+
// → spoken day + Bangla month (e.g. পয়লা বৈশাখ … on Pohela Baishakh)
|
|
424
|
+
|
|
425
|
+
<BanglaDate value="31 March 2026" />
|
|
426
|
+
// → <time dateTime="2026-03-31">17 Chaitra 1432</time> (example; depends on date)
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
All components render semantic `<time>` elements with `dateTime` and `aria-label` attributes. They are SSR-safe, tree-shakeable, and have zero runtime dependencies beyond React.
|
|
430
|
+
|
|
431
|
+
## What `Intl.DateTimeFormat` cannot do
|
|
432
|
+
|
|
433
|
+
| Feature | Intl | @coreify/tarikh |
|
|
434
|
+
| ------------------------------- | ------- | --------------- |
|
|
435
|
+
| Bangla calendar (বৈশাখ → চৈত্র) | No | Yes |
|
|
436
|
+
| Bangla digits in dates | Partial | Yes |
|
|
437
|
+
| Hybrid formatting (mixed en/bn) | No | Yes |
|
|
438
|
+
| Bangla calendar date parsing | No | Yes |
|
|
439
|
+
| Relative time in Bangla | No | Yes |
|
|
440
|
+
| SSR-safe React components | N/A | Yes |
|
|
441
|
+
|
|
442
|
+
## TypeScript
|
|
443
|
+
|
|
444
|
+
Fully typed with strict mode. Core option interfaces and value types are exported from `@coreify/tarikh`.
|
|
445
|
+
|
|
446
|
+
```ts
|
|
447
|
+
import type {
|
|
448
|
+
DateInput,
|
|
449
|
+
DayFormat,
|
|
450
|
+
MonthFormat,
|
|
451
|
+
Locale,
|
|
452
|
+
Language,
|
|
453
|
+
YearFormat,
|
|
454
|
+
WeekdayFormat,
|
|
455
|
+
TimeFormat,
|
|
456
|
+
BanglaCalendarOptions,
|
|
457
|
+
RelativeTimeOptions,
|
|
458
|
+
BanglaCalendarFormatOptions,
|
|
459
|
+
BanglaCalendarDayFormat,
|
|
460
|
+
BanglaCalendarDaySpokenVariant,
|
|
461
|
+
BanglaDayFormatOptions,
|
|
462
|
+
DateFormatOptions,
|
|
463
|
+
BanglaCalendarDate,
|
|
464
|
+
HybridDateFormatOptions
|
|
465
|
+
} from "@coreify/tarikh";
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
```ts
|
|
469
|
+
import type {
|
|
470
|
+
BanglaDateProps,
|
|
471
|
+
RelativeTimeProps,
|
|
472
|
+
TarikhProps
|
|
473
|
+
} from "@coreify/tarikh/react";
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
## License
|
|
477
|
+
|
|
478
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=["0","1","2","3","4","5","6","7","8","9"],e=["০","১","২","৩","৪","৫","৬","৭","৮","৯"],n=["January","February","March","April","May","June","July","August","September","October","November","December"],r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],o=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],s=["জানুয়ারি","ফেব্রুয়ারি","মার্চ","এপ্রিল","মে","জুন","জুলাই","আগস্ট","সেপ্টেম্বর","অক্টোবর","নভেম্বর","ডিসেম্বর"],u=["জানু","ফেব্রু","মার্চ","এপ্রি","মে","জুন","জুলা","আগ","সেপ্টে","অক্টো","নভে","ডিসে"],i=["রবিবার","সোমবার","মঙ্গলবার","বুধবার","বৃহস্পতিবার","শুক্রবার","শনিবার"],l=["রবি","সোম","মঙ্গল","বুধ","বৃহস্পতি","শুক্র","শনি"],g=["বৈশাখ","জ্যৈষ্ঠ","আষাঢ়","শ্রাবণ","ভাদ্র","আশ্বিন","কার্তিক","অগ্রহায়ণ","পৌষ","মাঘ","ফাল্গুন","চৈত্র"],c=["Baishakh","Jaishtho","Asharh","Shrabon","Bhadro","Ashshin","Kartik","Agrahayan","Poush","Magh","Falgun","Chaitra"],h=[31,31,31,31,31,30,30,30,30,30,30,30],d={second:"second",seconds:"seconds",minute:"minute",minutes:"minutes",hour:"hour",hours:"hours",day:"day",days:"days",week:"week",weeks:"weeks",month:"month",months:"months",year:"year",years:"years",ago:"ago",in:"in",justNow:"just now"},f={second:"সেকেন্ড",seconds:"সেকেন্ড",minute:"মিনিট",minutes:"মিনিট",hour:"ঘণ্টা",hours:"ঘণ্টা",day:"দিন",days:"দিন",week:"সপ্তাহ",weeks:"সপ্তাহ",month:"মাস",months:"মাস",year:"বছর",years:"বছর",ago:"আগে",in:"",justNow:"এইমাত্র"};function m(t){return String(t).replace(/\d/g,t=>e[Number(t)]??t)}function D(n){return String(n).replace(/[০-৯]/g,n=>{const r=e.indexOf(n);return r>=0?t[r]??n:n})}var M={jan:0,"jan.":0,january:0,"january,":0,feb:1,"feb.":1,february:1,"february,":1,mar:2,"mar.":2,march:2,"march,":2,apr:3,"apr.":3,april:3,"april,":3,may:4,"may,":4,jun:5,"jun.":5,june:5,"june,":5,jul:6,"jul.":6,july:6,"july,":6,aug:7,"aug.":7,august:7,"august,":7,sep:8,sept:8,"sep.":8,"sept.":8,september:8,"september,":8,oct:9,"oct.":9,october:9,"october,":9,nov:10,"nov.":10,november:10,"november,":10,dec:11,"dec.":11,december:11,"december,":11,"জানুয়ারি":0,"জানুয়ারি":0,"ফেব্রুয়ারি":1,"ফেব্রুয়ারি":1,"মার্চ":2,"এপ্রিল":3,"মে":4,"জুন":5,"জুলাই":6,"আগস্ট":7,"অগাস্ট":7,"সেপ্টেম্বর":8,"সেপ্টেম্বার":8,"অক্টোবর":9,"নভেম্বর":10,"নভেম্বার":10,"ডিসেম্বর":11,"ডিসেম্বার":11,"জানু":0,"ফেব্রু":1,"এপ্রি":3,"জুলা":6,"আগ":7,"সেপ্টে":8,"অক্টো":9,"নভে":10,"ডিসে":11};function p(t){const e=t.trim(),o=e.toLowerCase(),a=M[o];if(void 0!==a)return a;for(let t=0;t<n.length;t++)if(n[t].toLowerCase()===o)return t;for(let t=0;t<r.length;t++)if(r[t].toLowerCase()===o)return t;for(let t=0;t<s.length;t++)if(s[t]===e)return t;for(let t=0;t<u.length;t++)if(u[t]===e)return t;return-1}function y(t,e,n,r=0,o=0,a=0,s=0){const u=new Date(t,e,n,r,o,a,s);return u.getFullYear()!==t||u.getMonth()!==e||u.getDate()!==n||u.getHours()!==r||u.getMinutes()!==o||u.getSeconds()!==a||u.getMilliseconds()!==s?null:u}function b(t){return function(t){const e=t.trim().match(/^(\d{4})([-/.])(\d{1,2})\2(\d{1,2})$/);return e?y(Number(e[1]),Number(e[3])-1,Number(e[4])):null}(t)??function(t){const e=t.trim().match(/^(\d{4})-(\d{2})-(\d{2})(?:[T\s](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:?\d{2})?)$/);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),o=Number(e[3]),a=Number(e[4]??0),s=Number(e[5]??0),u=Number(e[6]??0),i=Number((e[7]??"0").padEnd(3,"0").slice(0,3)),l=e[8];if(void 0===l)return y(n,r-1,o,a,s,u,i);const g=l.match(/^([+-])(\d{2}):?(\d{2})$/),c="Z"===l?0:g?("+"===g[1]?1:-1)*(60*Number(g[2])+Number(g[3])):null;if(null===c)return null;const h=Date.UTC(n,r-1,o,a,s,u,i)-6e4*c,d=new Date(h),f=new Date(h+6e4*c);return f.getUTCFullYear()!==n||f.getUTCMonth()!==r-1||f.getUTCDate()!==o||f.getUTCHours()!==a||f.getUTCMinutes()!==s||f.getUTCSeconds()!==u||f.getUTCMilliseconds()!==i?null:d}(t)??function(t){const e=t.match(/^(\d{1,2})(?:st|nd|rd|th)?(?:\s+|-)(\S+)(?:\s+|-)(\d{2,4})$/);if(!e)return null;const n=Number(e[1]),r=e[2].replace(/,$/,""),o=e[3],a=p(r);if(-1===a)return null;let s=Number(o);return 2===o.length&&(s+=s>=50?1900:2e3),y(s,a,n)}(t)??function(t){const e=t.match(/^(\S+)\s+(\d{1,2})(?:st|nd|rd|th)?(?:,)?\s+(\d{2,4})$/);if(!e)return null;const n=e[1].replace(/,$/,""),r=Number(e[2]),o=e[3],a=p(n);if(-1===a)return null;let s=Number(o);return 2===o.length&&(s+=s>=50?1900:2e3),y(s,a,r)}(t)}function S(t){if(t instanceof Date){const e=t.getTime();if(Number.isNaN(e))throw new Error(`Invalid date input: ${String(t)}`);return new Date(e)}if("number"==typeof t){if(!Number.isFinite(t))throw new Error(`Invalid date input: ${String(t)}`);const e=new Date(t);if(Number.isNaN(e.getTime()))throw new Error(`Invalid date input: ${String(t)}`);return e}const e=b(D(t).trim());if(!e)throw new Error(`Invalid date input: ${String(t)}`);return e}function N(t,e){const n=S(t);return n.setDate(n.getDate()+e),n}function w(t,e){return new Date(t,e+1,0).getDate()}function $(t,e){const n=S(t),r=n.getFullYear(),o=n.getMonth()+e,a=r+Math.floor(o/12),s=(o%12+12)%12,u=Math.min(n.getDate(),w(a,s));return n.setFullYear(a,s,u),n}function x(t,e){const n=S(t),r=n.getFullYear()+e,o=Math.min(n.getDate(),w(r,n.getMonth()));return n.setFullYear(r,n.getMonth(),o),n}function Y(t){const e=[...h];return function(t){return(e=t+594)%4==0&&e%100!=0||e%400==0;var e}(t)&&(e[10]=31),e}function T(t,e){const n=e?.locale??"en-BD",r=S(t),o=r.getFullYear(),a=r.getMonth(),s=r.getDate(),u=new Date(o,3,14),i=a<3||3===a&&s<14,l=i?o-594:o-593,h=function(t,e){const n=Date.UTC(t.getFullYear(),t.getMonth(),t.getDate()),r=Date.UTC(e.getFullYear(),e.getMonth(),e.getDate());return Math.floor((r-n)/864e5)}(i?new Date(o-1,3,14):u,r)+1,d=Y(l);let f=h,D=0;for(let t=0;t<d.length;t++){const e=d[t];if(f<=e){D=t;break}f-=e}const M=D+1;return"bn-BD"===n?{day:m(f),month:g[D],monthIndex:M,year:m(l)}:{day:f,month:c[D],monthIndex:M,year:l}}function A(t,e,n){const r=function(t,e,n){if(!Number.isInteger(t)||!Number.isInteger(e)||!Number.isInteger(n))throw new Error("Invalid Bangla calendar date.");if(e<1||e>12)throw new Error("Invalid Bangla calendar month index. Must be 1-12.");const r=Y(n),o=r[e-1];if(t<1||t>o)throw new Error(`Invalid Bangla calendar day. Month ${e} of year ${n} has ${o} days.`);return r}(t,e,n),o=new Date(n+593,3,14);let a=t-1;for(let t=0;t<e-1;t++)a+=r[t];const s=new Date(o);return s.setDate(s.getDate()+a),s}function H(t){const e=m(t);return 1===t?`${e}লা`:2===t||3===t?`${e}রা`:4===t?`${e}ঠা`:t>=19?`${e}শে`:`${e}ই`}function B(t,e){return"spoken"===(e?.format??"ordinal")?function(t,e="pohela"){switch(t){case 1:return"poyla"===e?"পয়লা":"পহেলা";case 2:return"দোসরা";case 3:return"তেসরা";case 4:return"চৌঠা";default:return H(t)}}(t,e?.variant):H(t)}function F(t,e){return"2-digit"===e?String(t).padStart(2,"0"):String(t)}function v(t,e,n){if("bn-BD"===e)return t<12?"পূর্বাহ্ণ":"অপরাহ্ণ";const r=t<12?"AM":"PM";return n?r.toLowerCase():r}var E={baishakh:1,boishakh:1,boishak:1,boisakh:1,jaishtho:2,jaishtha:2,jaistha:2,joishtho:2,jyoishtho:2,jyoistho:2,jyeshtho:2,ashar:3,asadh:3,asharh:3,srabon:4,shraban:4,shrabon:4,sraban:4,bhadro:5,ashin:6,ashwin:6,ashshin:6,kartik:7,ograyon:8,ograyan:8,ogrohayon:8,ograhayon:8,agrahayan:8,aghrayan:8,pous:9,poush:9,mag:10,magh:10,falgoon:11,falgun:11,choitra:12,chaitra:12,choitro:12},_={"বৈশাখ":1,"জৈষ্ঠ":2,"জ্যৈষ্ঠ":2,"আষাঢ়":3,"আষাঢ়":3,"শ্রাবণ":4,"ভাদ্র":5,"আশ্বিন":6,"কার্তিক":7,"অগ্রহায়ণ":8,"অগ্রহায়ণ":8,"অঘ্রাণ":8,"অগ্রায়ণ":8,"অগ্রায়ণ":8,"পৌষ":9,"পৌস":9,"মাঘ":10,"ফাল্গুন":11,"চৈত্র":12};var L=1e3,I=36e5,j=24*I,k=[{threshold:7*j,singular:"week",plural:"weeks"},{threshold:j,singular:"day",plural:"days"},{threshold:I,singular:"hour",plural:"hours"},{threshold:6e4,singular:"minute",plural:"minutes"},{threshold:L,singular:"second",plural:"seconds"}];function C(t,e){return new Date(t,e+1,0).getDate()}function O(t,e){let n=t.getFullYear()-e.getFullYear();const r=function(t,e){const n=t.getFullYear()+e,r=t.getMonth(),o=Math.min(t.getDate(),C(n,r));return new Date(n,r,o,t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds())}(e,n);return r>t&&(n-=1),n}function G(t,e){let n=12*(t.getFullYear()-e.getFullYear())+(t.getMonth()-e.getMonth());const r=function(t,e){const n=t.getFullYear(),r=t.getMonth()+e,o=n+Math.floor(r/12),a=(r%12+12)%12,s=Math.min(t.getDate(),C(o,a));return new Date(o,a,s,t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds())}(e,n);return r>t&&(n-=1),n}function U(t,e,n,r,o){const a="bn-BD"===o,s=a?m(t):String(t),u=1===t?e:n;return a?r?`${s} ${u} আগে`:`${s} ${u} পরে`:r?`${s} ${u} ago`:`in ${s} ${u}`}function R(t,e,n){return"bn-BD"===n?"day"===t?e?"গতকাল":"আগামীকাল":"week"===t?e?"গত সপ্তাহে":"আগামী সপ্তাহে":"month"===t?e?"গত মাসে":"আগামী মাসে":e?"গত বছর":"আগামী বছর":"day"===t?e?"yesterday":"tomorrow":"week"===t?e?"last week":"next week":"month"===t?e?"last month":"next month":e?"last year":"next year"}exports.BANGLA_CALENDAR_MONTHS=g,exports.BANGLA_CALENDAR_MONTHS_EN=c,exports.BANGLA_CALENDAR_MONTH_DAYS=h,exports.BANGLA_DIGITS=e,exports.BANGLA_MONTHS_FULL=s,exports.BANGLA_MONTHS_SHORT=u,exports.BANGLA_WEEKDAYS_FULL=i,exports.BANGLA_WEEKDAYS_SHORT=l,exports.BOISHAKH_START_DAY=14,exports.BOISHAKH_START_MONTH=3,exports.ENGLISH_DIGITS=t,exports.ENGLISH_MONTHS_FULL=n,exports.ENGLISH_MONTHS_SHORT=r,exports.ENGLISH_WEEKDAYS_FULL=o,exports.ENGLISH_WEEKDAYS_SHORT=a,exports.RELATIVE_TIME_BN=f,exports.RELATIVE_TIME_EN=d,exports.addDays=N,exports.addMonths=$,exports.addYears=x,exports.endOfDay=function(t){const e=S(t);return e.setHours(23,59,59,999),e},exports.endOfMonth=function(t){const e=S(t);return e.setMonth(e.getMonth()+1,0),e.setHours(23,59,59,999),e},exports.endOfYear=function(t){const e=S(t);return e.setMonth(11,31),e.setHours(23,59,59,999),e},exports.format=function(t,e,g){const c=S(t),h=g?.locale??"en-BD",d="bn-BD"===h,f=c.getDate(),D=c.getMonth(),M=c.getFullYear(),p=d?s:n,y=d?u:r,b=d?i:o,N=d?l:a,w=c.getHours(),$=w%12||12,x={dddd:b[c.getDay()],ddd:N[c.getDay()],MMMM:p[D],MMM:y[D],MM:String(D+1).padStart(2,"0"),M:String(D+1),DD:String(f).padStart(2,"0"),D:String(f),HH:String(w).padStart(2,"0"),H:String(w),hh:String($).padStart(2,"0"),h:String($),mm:String(c.getMinutes()).padStart(2,"0"),m:String(c.getMinutes()),ss:String(c.getSeconds()).padStart(2,"0"),s:String(c.getSeconds()),A:v(w,h,!1),a:v(w,h,!0),YYYY:String(M),YY:String(M).slice(-2)},Y=e.replace(/dddd|ddd|MMMM|MMM|MM|M|DD|D|YYYY|YY|HH|H|hh|h|mm|m|ss|s|A|a/g,t=>x[t]);return d?m(Y):Y},exports.formatBanglaCalendar=function(t,e){const n=e?.locale??"en-BD",r=e?.format??"ordinal",o=e?.variant,a=T(t,{locale:"en-BD"});if("bn-BD"===n){const t=a.monthIndex-1,e={format:r};return void 0!==o&&(e.variant=o),`${B(a.day,e)} ${g[t]} ${m(a.year)}`}return`${a.day} ${a.month} ${a.year}`},exports.formatBanglaCalendarDay=B,exports.formatDate=function(t,e){const g=S(t),c=e?.locale??"en-BD",h=e?.month??"short",d=e?.year??"numeric",f=e?.day??"numeric",D=e?.weekday,M=e?.hour,p=e?.minute,y=e?.second,b=void 0!==M||void 0!==p||void 0!==y,N="bn-BD"===c,w=g.getDate(),$=g.getMonth(),x=g.getFullYear(),Y=`${"2-digit"===f?String(w).padStart(2,"0"):String(w)} ${(N?"short"===h?u:s:"short"===h?r:n)[$]} ${"2-digit"===d?String(x).slice(-2):String(x)}`,T=void 0!==D?`${(N?"short"===D?l:i:"short"===D?a:o)[g.getDay()]}, `:"";let A="";if(b){const t=e?.hour12??!1,n=g.getHours(),r=p??(void 0!==y?"2-digit":void 0);A=`${F(t?n%12||12:n,M??"numeric")}${void 0!==r?`:${F(g.getMinutes(),r)}`:""}${void 0!==y?`:${F(g.getSeconds(),y)}`:""}${t?` ${v(n,c,!1)}`:""}`}const H=`${T}${Y}${A?`, ${A}`:""}`;return N?m(H):H},exports.formatHybridDate=function(t,e){const o=S(t),a=e?.digits??"en",i=e?.month??"bn",l=e?.year??"en",g=e?.day??a,c=e?.monthFormat??"long",h=o.getDate(),d=o.getMonth(),f=o.getFullYear(),D="bn"===i?"short"===c?u:s:"short"===c?r:n;return`${"bn"===g?m(h):String(h)} ${D[d]} ${"bn"===l?m(f):String(f)}`},exports.fromBanglaCalendar=A,exports.fromNow=function(t,e){const n=S(t),r=e?.locale??"en-BD",o=e?.numeric??"always",a="bn-BD"===r?f:d,s=Date.now()-n.getTime(),u=Math.abs(s),i=s>0,l=new Date,g=n.getFullYear()===l.getFullYear()&&n.getMonth()===l.getMonth()&&n.getDate()===l.getDate(),c=i?l:n,h=i?n:l;if(u<L)return a.justNow;if("auto"===o&&g)return function(t){return"bn-BD"===t?"আজ":"today"}(r);const m=O(c,h);if(m>=1){if("auto"===o&&1===m){const t=R("year",i,r);if(null!==t)return t}return U(m,a.year,a.years,i,r)}const D=G(c,h);if(D>=1){if("auto"===o&&1===D){const t=R("month",i,r);if(null!==t)return t}return U(D,a.month,a.months,i,r)}for(const t of k)if(u>=t.threshold){const e=Math.floor(u/t.threshold);if("auto"===o&&1===e&&("day"===t.singular||"week"===t.singular)){const e=R(t.singular,i,r);if(null!==e)return e}return U(e,a[t.singular],a[t.plural],i,r)}return a.justNow},exports.getBanglaMonth=function(t,e="long"){const n=t-1;if(n<0||n>11)throw new Error(`Invalid month number: ${t}. Must be 1-12.`);return"short"===e?u[n]:s[n]},exports.isToday=function(t){const e=S(t),n=new Date;return e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate()},exports.isTomorrow=function(t){const e=S(t),n=new Date;return n.setDate(n.getDate()+1),e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate()},exports.isYesterday=function(t){const e=S(t),n=new Date;return n.setDate(n.getDate()-1),e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate()},exports.parseDate=function(t,e){if(t instanceof Date)return Number.isNaN(t.getTime())?null:new Date(t.getTime());if("number"==typeof t){const e=new Date(t);return Number.isNaN(e.getTime())?null:e}const n=D(t).trim();return"bangla"===e?.calendar?function(t){const e=t.match(/^(\S+),?\s+(\S+),?\s+(\d{4})$/);if(!e)return null;const n=function(t){const e={"পহেলা":1,"পয়লা":1,"পয়লা":1,"দোসরা":2,"তেসরা":3,"চৌঠা":4}[t];if(void 0!==e)return e;const n=t.match(/^(\d{1,2})(?:লা|রা|ঠা|ই|শে)$/);if(n)return Number(n[1]);const r=Number(t);return Number.isInteger(r)&&r>=1&&r<=31?r:null}(e[1].replace(/,$/,""));if(null===n)return null;const r=function(t){const e=t.toLowerCase();for(let e=0;e<g.length;e++)if(g[e]===t)return e+1;const n=_[t];if(void 0!==n)return n;for(let t=0;t<c.length;t++)if(c[t].toLowerCase()===e)return t+1;const r=E[e];return void 0!==r?r:-1}(e[2].replace(/,$/,""));if(-1===r)return null;const o=Number(e[3]);try{return A(n,r,o)}catch{return null}}(n):b(n)},exports.startOfDay=function(t){const e=S(t);return e.setHours(0,0,0,0),e},exports.startOfMonth=function(t){const e=S(t);return e.setDate(1),e.setHours(0,0,0,0),e},exports.startOfYear=function(t){const e=S(t);return e.setMonth(0,1),e.setHours(0,0,0,0),e},exports.subDays=function(t,e){return N(t,-e)},exports.subMonths=function(t,e){return $(t,-e)},exports.subYears=function(t,e){return x(t,-e)},exports.toBanglaCalendar=T,exports.toBanglaDigits=m,exports.toDate=S,exports.toEnglishDigits=D;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
type Locale = "en-BD" | "bn-BD";
|
|
2
|
+
type Language = "en" | "bn";
|
|
3
|
+
type MonthFormat = "short" | "long";
|
|
4
|
+
type YearFormat = "numeric" | "2-digit";
|
|
5
|
+
type DayFormat = "numeric" | "2-digit";
|
|
6
|
+
type WeekdayFormat = "short" | "long";
|
|
7
|
+
type TimeFormat = "numeric" | "2-digit";
|
|
8
|
+
type DateInput = Date | string | number;
|
|
9
|
+
interface DateFormatOptions {
|
|
10
|
+
locale?: Locale;
|
|
11
|
+
month?: MonthFormat;
|
|
12
|
+
year?: YearFormat;
|
|
13
|
+
day?: DayFormat;
|
|
14
|
+
weekday?: WeekdayFormat;
|
|
15
|
+
hour?: TimeFormat;
|
|
16
|
+
minute?: TimeFormat;
|
|
17
|
+
second?: TimeFormat;
|
|
18
|
+
hour12?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface TokenFormatOptions {
|
|
21
|
+
locale?: Locale;
|
|
22
|
+
}
|
|
23
|
+
interface HybridDateFormatOptions {
|
|
24
|
+
digits?: Language;
|
|
25
|
+
month?: Language;
|
|
26
|
+
year?: Language;
|
|
27
|
+
day?: Language;
|
|
28
|
+
monthFormat?: MonthFormat;
|
|
29
|
+
}
|
|
30
|
+
interface RelativeTimeOptions {
|
|
31
|
+
locale?: Locale;
|
|
32
|
+
numeric?: "always" | "auto";
|
|
33
|
+
}
|
|
34
|
+
interface DateParseOptions {
|
|
35
|
+
calendar?: "gregorian" | "bangla";
|
|
36
|
+
}
|
|
37
|
+
interface BanglaCalendarOptions {
|
|
38
|
+
locale?: Locale;
|
|
39
|
+
}
|
|
40
|
+
interface BanglaCalendarDate {
|
|
41
|
+
day: number;
|
|
42
|
+
month: string;
|
|
43
|
+
monthIndex: number;
|
|
44
|
+
year: number;
|
|
45
|
+
}
|
|
46
|
+
interface BanglaCalendarDateLocalized {
|
|
47
|
+
day: string;
|
|
48
|
+
month: string;
|
|
49
|
+
monthIndex: number;
|
|
50
|
+
year: string;
|
|
51
|
+
}
|
|
52
|
+
interface BanglaCalendarFormatOptions {
|
|
53
|
+
locale?: Locale;
|
|
54
|
+
format?: BanglaCalendarDayFormat;
|
|
55
|
+
variant?: BanglaCalendarDaySpokenVariant;
|
|
56
|
+
}
|
|
57
|
+
type BanglaCalendarDayFormat = "ordinal" | "spoken";
|
|
58
|
+
type BanglaCalendarDaySpokenVariant = "pohela" | "poyla";
|
|
59
|
+
interface BanglaDayFormatOptions {
|
|
60
|
+
format?: BanglaCalendarDayFormat;
|
|
61
|
+
variant?: BanglaCalendarDaySpokenVariant;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare function toBanglaCalendar(input: DateInput, options: BanglaCalendarOptions & {
|
|
65
|
+
locale: "bn-BD";
|
|
66
|
+
}): BanglaCalendarDateLocalized;
|
|
67
|
+
declare function toBanglaCalendar(input: DateInput, options?: BanglaCalendarOptions): BanglaCalendarDate;
|
|
68
|
+
declare function fromBanglaCalendar(day: number, monthIndex: number, year: number): Date;
|
|
69
|
+
|
|
70
|
+
declare const ENGLISH_DIGITS: readonly ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
|
|
71
|
+
declare const BANGLA_DIGITS: readonly ["০", "১", "২", "৩", "৪", "৫", "৬", "৭", "৮", "৯"];
|
|
72
|
+
declare const ENGLISH_MONTHS_FULL: readonly ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
73
|
+
declare const ENGLISH_MONTHS_SHORT: readonly ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
74
|
+
declare const ENGLISH_WEEKDAYS_FULL: readonly ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
75
|
+
declare const ENGLISH_WEEKDAYS_SHORT: readonly ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
76
|
+
declare const BANGLA_MONTHS_FULL: readonly ["জানুয়ারি", "ফেব্রুয়ারি", "মার্চ", "এপ্রিল", "মে", "জুন", "জুলাই", "আগস্ট", "সেপ্টেম্বর", "অক্টোবর", "নভেম্বর", "ডিসেম্বর"];
|
|
77
|
+
declare const BANGLA_MONTHS_SHORT: readonly ["জানু", "ফেব্রু", "মার্চ", "এপ্রি", "মে", "জুন", "জুলা", "আগ", "সেপ্টে", "অক্টো", "নভে", "ডিসে"];
|
|
78
|
+
declare const BANGLA_WEEKDAYS_FULL: readonly ["রবিবার", "সোমবার", "মঙ্গলবার", "বুধবার", "বৃহস্পতিবার", "শুক্রবার", "শনিবার"];
|
|
79
|
+
declare const BANGLA_WEEKDAYS_SHORT: readonly ["রবি", "সোম", "মঙ্গল", "বুধ", "বৃহস্পতি", "শুক্র", "শনি"];
|
|
80
|
+
declare const BANGLA_CALENDAR_MONTHS: readonly ["বৈশাখ", "জ্যৈষ্ঠ", "আষাঢ়", "শ্রাবণ", "ভাদ্র", "আশ্বিন", "কার্তিক", "অগ্রহায়ণ", "পৌষ", "মাঘ", "ফাল্গুন", "চৈত্র"];
|
|
81
|
+
declare const BANGLA_CALENDAR_MONTHS_EN: readonly ["Baishakh", "Jaishtho", "Asharh", "Shrabon", "Bhadro", "Ashshin", "Kartik", "Agrahayan", "Poush", "Magh", "Falgun", "Chaitra"];
|
|
82
|
+
declare const BANGLA_CALENDAR_MONTH_DAYS: readonly [31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30, 30];
|
|
83
|
+
declare const BOISHAKH_START_MONTH = 3;
|
|
84
|
+
declare const BOISHAKH_START_DAY = 14;
|
|
85
|
+
declare const RELATIVE_TIME_EN: {
|
|
86
|
+
readonly second: "second";
|
|
87
|
+
readonly seconds: "seconds";
|
|
88
|
+
readonly minute: "minute";
|
|
89
|
+
readonly minutes: "minutes";
|
|
90
|
+
readonly hour: "hour";
|
|
91
|
+
readonly hours: "hours";
|
|
92
|
+
readonly day: "day";
|
|
93
|
+
readonly days: "days";
|
|
94
|
+
readonly week: "week";
|
|
95
|
+
readonly weeks: "weeks";
|
|
96
|
+
readonly month: "month";
|
|
97
|
+
readonly months: "months";
|
|
98
|
+
readonly year: "year";
|
|
99
|
+
readonly years: "years";
|
|
100
|
+
readonly ago: "ago";
|
|
101
|
+
readonly in: "in";
|
|
102
|
+
readonly justNow: "just now";
|
|
103
|
+
};
|
|
104
|
+
declare const RELATIVE_TIME_BN: {
|
|
105
|
+
readonly second: "সেকেন্ড";
|
|
106
|
+
readonly seconds: "সেকেন্ড";
|
|
107
|
+
readonly minute: "মিনিট";
|
|
108
|
+
readonly minutes: "মিনিট";
|
|
109
|
+
readonly hour: "ঘণ্টা";
|
|
110
|
+
readonly hours: "ঘণ্টা";
|
|
111
|
+
readonly day: "দিন";
|
|
112
|
+
readonly days: "দিন";
|
|
113
|
+
readonly week: "সপ্তাহ";
|
|
114
|
+
readonly weeks: "সপ্তাহ";
|
|
115
|
+
readonly month: "মাস";
|
|
116
|
+
readonly months: "মাস";
|
|
117
|
+
readonly year: "বছর";
|
|
118
|
+
readonly years: "বছর";
|
|
119
|
+
readonly ago: "আগে";
|
|
120
|
+
readonly in: "";
|
|
121
|
+
readonly justNow: "এইমাত্র";
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
declare function toBanglaDigits(input: number | string): string;
|
|
125
|
+
declare function toEnglishDigits(input: number | string): string;
|
|
126
|
+
|
|
127
|
+
declare function formatBanglaCalendarDay(day: number, options?: BanglaDayFormatOptions): string;
|
|
128
|
+
declare function formatDate(input: DateInput, options?: DateFormatOptions): string;
|
|
129
|
+
declare function format(input: DateInput, template: string, options?: TokenFormatOptions): string;
|
|
130
|
+
declare function formatBanglaCalendar(input: DateInput, options?: BanglaCalendarFormatOptions): string;
|
|
131
|
+
declare function formatHybridDate(input: DateInput, options?: HybridDateFormatOptions): string;
|
|
132
|
+
|
|
133
|
+
declare function parseDate(input: DateInput, options?: DateParseOptions): Date | null;
|
|
134
|
+
|
|
135
|
+
declare function fromNow(input: DateInput, options?: RelativeTimeOptions): string;
|
|
136
|
+
|
|
137
|
+
declare function toDate(input: DateInput): Date;
|
|
138
|
+
declare function isToday(input: DateInput): boolean;
|
|
139
|
+
declare function isYesterday(input: DateInput): boolean;
|
|
140
|
+
declare function isTomorrow(input: DateInput): boolean;
|
|
141
|
+
declare function startOfDay(input: DateInput): Date;
|
|
142
|
+
declare function endOfDay(input: DateInput): Date;
|
|
143
|
+
declare function addDays(input: DateInput, days: number): Date;
|
|
144
|
+
declare function subDays(input: DateInput, days: number): Date;
|
|
145
|
+
declare function addMonths(input: DateInput, months: number): Date;
|
|
146
|
+
declare function subMonths(input: DateInput, months: number): Date;
|
|
147
|
+
declare function addYears(input: DateInput, years: number): Date;
|
|
148
|
+
declare function subYears(input: DateInput, years: number): Date;
|
|
149
|
+
declare function startOfMonth(input: DateInput): Date;
|
|
150
|
+
declare function endOfMonth(input: DateInput): Date;
|
|
151
|
+
declare function startOfYear(input: DateInput): Date;
|
|
152
|
+
declare function endOfYear(input: DateInput): Date;
|
|
153
|
+
declare function getBanglaMonth(month: number, format?: MonthFormat): string;
|
|
154
|
+
|
|
155
|
+
export { BANGLA_CALENDAR_MONTHS, BANGLA_CALENDAR_MONTHS_EN, BANGLA_CALENDAR_MONTH_DAYS, BANGLA_DIGITS, BANGLA_MONTHS_FULL, BANGLA_MONTHS_SHORT, BANGLA_WEEKDAYS_FULL, BANGLA_WEEKDAYS_SHORT, BOISHAKH_START_DAY, BOISHAKH_START_MONTH, type BanglaCalendarDate, type BanglaCalendarDateLocalized, type BanglaCalendarDayFormat, type BanglaCalendarDaySpokenVariant, type BanglaCalendarFormatOptions, type BanglaCalendarOptions, type BanglaDayFormatOptions, type DateFormatOptions, type DateInput, type DateParseOptions, type DayFormat, ENGLISH_DIGITS, ENGLISH_MONTHS_FULL, ENGLISH_MONTHS_SHORT, ENGLISH_WEEKDAYS_FULL, ENGLISH_WEEKDAYS_SHORT, type HybridDateFormatOptions, type Language, type Locale, type MonthFormat, RELATIVE_TIME_BN, RELATIVE_TIME_EN, type RelativeTimeOptions, type TimeFormat, type TokenFormatOptions, type WeekdayFormat, type YearFormat, addDays, addMonths, addYears, endOfDay, endOfMonth, endOfYear, format, formatBanglaCalendar, formatBanglaCalendarDay, formatDate, formatHybridDate, fromBanglaCalendar, fromNow, getBanglaMonth, isToday, isTomorrow, isYesterday, parseDate, startOfDay, startOfMonth, startOfYear, subDays, subMonths, subYears, toBanglaCalendar, toBanglaDigits, toDate, toEnglishDigits };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
type Locale = "en-BD" | "bn-BD";
|
|
2
|
+
type Language = "en" | "bn";
|
|
3
|
+
type MonthFormat = "short" | "long";
|
|
4
|
+
type YearFormat = "numeric" | "2-digit";
|
|
5
|
+
type DayFormat = "numeric" | "2-digit";
|
|
6
|
+
type WeekdayFormat = "short" | "long";
|
|
7
|
+
type TimeFormat = "numeric" | "2-digit";
|
|
8
|
+
type DateInput = Date | string | number;
|
|
9
|
+
interface DateFormatOptions {
|
|
10
|
+
locale?: Locale;
|
|
11
|
+
month?: MonthFormat;
|
|
12
|
+
year?: YearFormat;
|
|
13
|
+
day?: DayFormat;
|
|
14
|
+
weekday?: WeekdayFormat;
|
|
15
|
+
hour?: TimeFormat;
|
|
16
|
+
minute?: TimeFormat;
|
|
17
|
+
second?: TimeFormat;
|
|
18
|
+
hour12?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface TokenFormatOptions {
|
|
21
|
+
locale?: Locale;
|
|
22
|
+
}
|
|
23
|
+
interface HybridDateFormatOptions {
|
|
24
|
+
digits?: Language;
|
|
25
|
+
month?: Language;
|
|
26
|
+
year?: Language;
|
|
27
|
+
day?: Language;
|
|
28
|
+
monthFormat?: MonthFormat;
|
|
29
|
+
}
|
|
30
|
+
interface RelativeTimeOptions {
|
|
31
|
+
locale?: Locale;
|
|
32
|
+
numeric?: "always" | "auto";
|
|
33
|
+
}
|
|
34
|
+
interface DateParseOptions {
|
|
35
|
+
calendar?: "gregorian" | "bangla";
|
|
36
|
+
}
|
|
37
|
+
interface BanglaCalendarOptions {
|
|
38
|
+
locale?: Locale;
|
|
39
|
+
}
|
|
40
|
+
interface BanglaCalendarDate {
|
|
41
|
+
day: number;
|
|
42
|
+
month: string;
|
|
43
|
+
monthIndex: number;
|
|
44
|
+
year: number;
|
|
45
|
+
}
|
|
46
|
+
interface BanglaCalendarDateLocalized {
|
|
47
|
+
day: string;
|
|
48
|
+
month: string;
|
|
49
|
+
monthIndex: number;
|
|
50
|
+
year: string;
|
|
51
|
+
}
|
|
52
|
+
interface BanglaCalendarFormatOptions {
|
|
53
|
+
locale?: Locale;
|
|
54
|
+
format?: BanglaCalendarDayFormat;
|
|
55
|
+
variant?: BanglaCalendarDaySpokenVariant;
|
|
56
|
+
}
|
|
57
|
+
type BanglaCalendarDayFormat = "ordinal" | "spoken";
|
|
58
|
+
type BanglaCalendarDaySpokenVariant = "pohela" | "poyla";
|
|
59
|
+
interface BanglaDayFormatOptions {
|
|
60
|
+
format?: BanglaCalendarDayFormat;
|
|
61
|
+
variant?: BanglaCalendarDaySpokenVariant;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare function toBanglaCalendar(input: DateInput, options: BanglaCalendarOptions & {
|
|
65
|
+
locale: "bn-BD";
|
|
66
|
+
}): BanglaCalendarDateLocalized;
|
|
67
|
+
declare function toBanglaCalendar(input: DateInput, options?: BanglaCalendarOptions): BanglaCalendarDate;
|
|
68
|
+
declare function fromBanglaCalendar(day: number, monthIndex: number, year: number): Date;
|
|
69
|
+
|
|
70
|
+
declare const ENGLISH_DIGITS: readonly ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
|
|
71
|
+
declare const BANGLA_DIGITS: readonly ["০", "১", "২", "৩", "৪", "৫", "৬", "৭", "৮", "৯"];
|
|
72
|
+
declare const ENGLISH_MONTHS_FULL: readonly ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
73
|
+
declare const ENGLISH_MONTHS_SHORT: readonly ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
74
|
+
declare const ENGLISH_WEEKDAYS_FULL: readonly ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
75
|
+
declare const ENGLISH_WEEKDAYS_SHORT: readonly ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
76
|
+
declare const BANGLA_MONTHS_FULL: readonly ["জানুয়ারি", "ফেব্রুয়ারি", "মার্চ", "এপ্রিল", "মে", "জুন", "জুলাই", "আগস্ট", "সেপ্টেম্বর", "অক্টোবর", "নভেম্বর", "ডিসেম্বর"];
|
|
77
|
+
declare const BANGLA_MONTHS_SHORT: readonly ["জানু", "ফেব্রু", "মার্চ", "এপ্রি", "মে", "জুন", "জুলা", "আগ", "সেপ্টে", "অক্টো", "নভে", "ডিসে"];
|
|
78
|
+
declare const BANGLA_WEEKDAYS_FULL: readonly ["রবিবার", "সোমবার", "মঙ্গলবার", "বুধবার", "বৃহস্পতিবার", "শুক্রবার", "শনিবার"];
|
|
79
|
+
declare const BANGLA_WEEKDAYS_SHORT: readonly ["রবি", "সোম", "মঙ্গল", "বুধ", "বৃহস্পতি", "শুক্র", "শনি"];
|
|
80
|
+
declare const BANGLA_CALENDAR_MONTHS: readonly ["বৈশাখ", "জ্যৈষ্ঠ", "আষাঢ়", "শ্রাবণ", "ভাদ্র", "আশ্বিন", "কার্তিক", "অগ্রহায়ণ", "পৌষ", "মাঘ", "ফাল্গুন", "চৈত্র"];
|
|
81
|
+
declare const BANGLA_CALENDAR_MONTHS_EN: readonly ["Baishakh", "Jaishtho", "Asharh", "Shrabon", "Bhadro", "Ashshin", "Kartik", "Agrahayan", "Poush", "Magh", "Falgun", "Chaitra"];
|
|
82
|
+
declare const BANGLA_CALENDAR_MONTH_DAYS: readonly [31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30, 30];
|
|
83
|
+
declare const BOISHAKH_START_MONTH = 3;
|
|
84
|
+
declare const BOISHAKH_START_DAY = 14;
|
|
85
|
+
declare const RELATIVE_TIME_EN: {
|
|
86
|
+
readonly second: "second";
|
|
87
|
+
readonly seconds: "seconds";
|
|
88
|
+
readonly minute: "minute";
|
|
89
|
+
readonly minutes: "minutes";
|
|
90
|
+
readonly hour: "hour";
|
|
91
|
+
readonly hours: "hours";
|
|
92
|
+
readonly day: "day";
|
|
93
|
+
readonly days: "days";
|
|
94
|
+
readonly week: "week";
|
|
95
|
+
readonly weeks: "weeks";
|
|
96
|
+
readonly month: "month";
|
|
97
|
+
readonly months: "months";
|
|
98
|
+
readonly year: "year";
|
|
99
|
+
readonly years: "years";
|
|
100
|
+
readonly ago: "ago";
|
|
101
|
+
readonly in: "in";
|
|
102
|
+
readonly justNow: "just now";
|
|
103
|
+
};
|
|
104
|
+
declare const RELATIVE_TIME_BN: {
|
|
105
|
+
readonly second: "সেকেন্ড";
|
|
106
|
+
readonly seconds: "সেকেন্ড";
|
|
107
|
+
readonly minute: "মিনিট";
|
|
108
|
+
readonly minutes: "মিনিট";
|
|
109
|
+
readonly hour: "ঘণ্টা";
|
|
110
|
+
readonly hours: "ঘণ্টা";
|
|
111
|
+
readonly day: "দিন";
|
|
112
|
+
readonly days: "দিন";
|
|
113
|
+
readonly week: "সপ্তাহ";
|
|
114
|
+
readonly weeks: "সপ্তাহ";
|
|
115
|
+
readonly month: "মাস";
|
|
116
|
+
readonly months: "মাস";
|
|
117
|
+
readonly year: "বছর";
|
|
118
|
+
readonly years: "বছর";
|
|
119
|
+
readonly ago: "আগে";
|
|
120
|
+
readonly in: "";
|
|
121
|
+
readonly justNow: "এইমাত্র";
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
declare function toBanglaDigits(input: number | string): string;
|
|
125
|
+
declare function toEnglishDigits(input: number | string): string;
|
|
126
|
+
|
|
127
|
+
declare function formatBanglaCalendarDay(day: number, options?: BanglaDayFormatOptions): string;
|
|
128
|
+
declare function formatDate(input: DateInput, options?: DateFormatOptions): string;
|
|
129
|
+
declare function format(input: DateInput, template: string, options?: TokenFormatOptions): string;
|
|
130
|
+
declare function formatBanglaCalendar(input: DateInput, options?: BanglaCalendarFormatOptions): string;
|
|
131
|
+
declare function formatHybridDate(input: DateInput, options?: HybridDateFormatOptions): string;
|
|
132
|
+
|
|
133
|
+
declare function parseDate(input: DateInput, options?: DateParseOptions): Date | null;
|
|
134
|
+
|
|
135
|
+
declare function fromNow(input: DateInput, options?: RelativeTimeOptions): string;
|
|
136
|
+
|
|
137
|
+
declare function toDate(input: DateInput): Date;
|
|
138
|
+
declare function isToday(input: DateInput): boolean;
|
|
139
|
+
declare function isYesterday(input: DateInput): boolean;
|
|
140
|
+
declare function isTomorrow(input: DateInput): boolean;
|
|
141
|
+
declare function startOfDay(input: DateInput): Date;
|
|
142
|
+
declare function endOfDay(input: DateInput): Date;
|
|
143
|
+
declare function addDays(input: DateInput, days: number): Date;
|
|
144
|
+
declare function subDays(input: DateInput, days: number): Date;
|
|
145
|
+
declare function addMonths(input: DateInput, months: number): Date;
|
|
146
|
+
declare function subMonths(input: DateInput, months: number): Date;
|
|
147
|
+
declare function addYears(input: DateInput, years: number): Date;
|
|
148
|
+
declare function subYears(input: DateInput, years: number): Date;
|
|
149
|
+
declare function startOfMonth(input: DateInput): Date;
|
|
150
|
+
declare function endOfMonth(input: DateInput): Date;
|
|
151
|
+
declare function startOfYear(input: DateInput): Date;
|
|
152
|
+
declare function endOfYear(input: DateInput): Date;
|
|
153
|
+
declare function getBanglaMonth(month: number, format?: MonthFormat): string;
|
|
154
|
+
|
|
155
|
+
export { BANGLA_CALENDAR_MONTHS, BANGLA_CALENDAR_MONTHS_EN, BANGLA_CALENDAR_MONTH_DAYS, BANGLA_DIGITS, BANGLA_MONTHS_FULL, BANGLA_MONTHS_SHORT, BANGLA_WEEKDAYS_FULL, BANGLA_WEEKDAYS_SHORT, BOISHAKH_START_DAY, BOISHAKH_START_MONTH, type BanglaCalendarDate, type BanglaCalendarDateLocalized, type BanglaCalendarDayFormat, type BanglaCalendarDaySpokenVariant, type BanglaCalendarFormatOptions, type BanglaCalendarOptions, type BanglaDayFormatOptions, type DateFormatOptions, type DateInput, type DateParseOptions, type DayFormat, ENGLISH_DIGITS, ENGLISH_MONTHS_FULL, ENGLISH_MONTHS_SHORT, ENGLISH_WEEKDAYS_FULL, ENGLISH_WEEKDAYS_SHORT, type HybridDateFormatOptions, type Language, type Locale, type MonthFormat, RELATIVE_TIME_BN, RELATIVE_TIME_EN, type RelativeTimeOptions, type TimeFormat, type TokenFormatOptions, type WeekdayFormat, type YearFormat, addDays, addMonths, addYears, endOfDay, endOfMonth, endOfYear, format, formatBanglaCalendar, formatBanglaCalendarDay, formatDate, formatHybridDate, fromBanglaCalendar, fromNow, getBanglaMonth, isToday, isTomorrow, isYesterday, parseDate, startOfDay, startOfMonth, startOfYear, subDays, subMonths, subYears, toBanglaCalendar, toBanglaDigits, toDate, toEnglishDigits };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=["0","1","2","3","4","5","6","7","8","9"],e=["০","১","২","৩","৪","৫","৬","৭","৮","৯"],n=["January","February","March","April","May","June","July","August","September","October","November","December"],r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],o=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],u=["জানুয়ারি","ফেব্রুয়ারি","মার্চ","এপ্রিল","মে","জুন","জুলাই","আগস্ট","সেপ্টেম্বর","অক্টোবর","নভেম্বর","ডিসেম্বর"],s=["জানু","ফেব্রু","মার্চ","এপ্রি","মে","জুন","জুলা","আগ","সেপ্টে","অক্টো","নভে","ডিসে"],i=["রবিবার","সোমবার","মঙ্গলবার","বুধবার","বৃহস্পতিবার","শুক্রবার","শনিবার"],l=["রবি","সোম","মঙ্গল","বুধ","বৃহস্পতি","শুক্র","শনি"],c=["বৈশাখ","জ্যৈষ্ঠ","আষাঢ়","শ্রাবণ","ভাদ্র","আশ্বিন","কার্তিক","অগ্রহায়ণ","পৌষ","মাঘ","ফাল্গুন","চৈত্র"],g=["Baishakh","Jaishtho","Asharh","Shrabon","Bhadro","Ashshin","Kartik","Agrahayan","Poush","Magh","Falgun","Chaitra"],h=[31,31,31,31,31,30,30,30,30,30,30,30],d=3,f=14,m={second:"second",seconds:"seconds",minute:"minute",minutes:"minutes",hour:"hour",hours:"hours",day:"day",days:"days",week:"week",weeks:"weeks",month:"month",months:"months",year:"year",years:"years",ago:"ago",in:"in",justNow:"just now"},D={second:"সেকেন্ড",seconds:"সেকেন্ড",minute:"মিনিট",minutes:"মিনিট",hour:"ঘণ্টা",hours:"ঘণ্টা",day:"দিন",days:"দিন",week:"সপ্তাহ",weeks:"সপ্তাহ",month:"মাস",months:"মাস",year:"বছর",years:"বছর",ago:"আগে",in:"",justNow:"এইমাত্র"};function y(t){return String(t).replace(/\d/g,t=>e[Number(t)]??t)}function M(n){return String(n).replace(/[০-৯]/g,n=>{const r=e.indexOf(n);return r>=0?t[r]??n:n})}var b={jan:0,"jan.":0,january:0,"january,":0,feb:1,"feb.":1,february:1,"february,":1,mar:2,"mar.":2,march:2,"march,":2,apr:3,"apr.":3,april:3,"april,":3,may:4,"may,":4,jun:5,"jun.":5,june:5,"june,":5,jul:6,"jul.":6,july:6,"july,":6,aug:7,"aug.":7,august:7,"august,":7,sep:8,sept:8,"sep.":8,"sept.":8,september:8,"september,":8,oct:9,"oct.":9,october:9,"october,":9,nov:10,"nov.":10,november:10,"november,":10,dec:11,"dec.":11,december:11,"december,":11,"জানুয়ারি":0,"জানুয়ারি":0,"ফেব্রুয়ারি":1,"ফেব্রুয়ারি":1,"মার্চ":2,"এপ্রিল":3,"মে":4,"জুন":5,"জুলাই":6,"আগস্ট":7,"অগাস্ট":7,"সেপ্টেম্বর":8,"সেপ্টেম্বার":8,"অক্টোবর":9,"নভেম্বর":10,"নভেম্বার":10,"ডিসেম্বর":11,"ডিসেম্বার":11,"জানু":0,"ফেব্রু":1,"এপ্রি":3,"জুলা":6,"আগ":7,"সেপ্টে":8,"অক্টো":9,"নভে":10,"ডিসে":11};function w(t){const e=t.trim(),o=e.toLowerCase(),a=b[o];if(void 0!==a)return a;for(let t=0;t<n.length;t++)if(n[t].toLowerCase()===o)return t;for(let t=0;t<r.length;t++)if(r[t].toLowerCase()===o)return t;for(let t=0;t<u.length;t++)if(u[t]===e)return t;for(let t=0;t<s.length;t++)if(s[t]===e)return t;return-1}function $(t,e,n,r=0,o=0,a=0,u=0){const s=new Date(t,e,n,r,o,a,u);return s.getFullYear()!==t||s.getMonth()!==e||s.getDate()!==n||s.getHours()!==r||s.getMinutes()!==o||s.getSeconds()!==a||s.getMilliseconds()!==u?null:s}function S(t){return function(t){const e=t.trim().match(/^(\d{4})([-/.])(\d{1,2})\2(\d{1,2})$/);return e?$(Number(e[1]),Number(e[3])-1,Number(e[4])):null}(t)??function(t){const e=t.trim().match(/^(\d{4})-(\d{2})-(\d{2})(?:[T\s](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:?\d{2})?)$/);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),o=Number(e[3]),a=Number(e[4]??0),u=Number(e[5]??0),s=Number(e[6]??0),i=Number((e[7]??"0").padEnd(3,"0").slice(0,3)),l=e[8];if(void 0===l)return $(n,r-1,o,a,u,s,i);const c=l.match(/^([+-])(\d{2}):?(\d{2})$/),g="Z"===l?0:c?("+"===c[1]?1:-1)*(60*Number(c[2])+Number(c[3])):null;if(null===g)return null;const h=Date.UTC(n,r-1,o,a,u,s,i)-6e4*g,d=new Date(h),f=new Date(h+6e4*g);return f.getUTCFullYear()!==n||f.getUTCMonth()!==r-1||f.getUTCDate()!==o||f.getUTCHours()!==a||f.getUTCMinutes()!==u||f.getUTCSeconds()!==s||f.getUTCMilliseconds()!==i?null:d}(t)??function(t){const e=t.match(/^(\d{1,2})(?:st|nd|rd|th)?(?:\s+|-)(\S+)(?:\s+|-)(\d{2,4})$/);if(!e)return null;const n=Number(e[1]),r=e[2].replace(/,$/,""),o=e[3],a=w(r);if(-1===a)return null;let u=Number(o);return 2===o.length&&(u+=u>=50?1900:2e3),$(u,a,n)}(t)??function(t){const e=t.match(/^(\S+)\s+(\d{1,2})(?:st|nd|rd|th)?(?:,)?\s+(\d{2,4})$/);if(!e)return null;const n=e[1].replace(/,$/,""),r=Number(e[2]),o=e[3],a=w(n);if(-1===a)return null;let u=Number(o);return 2===o.length&&(u+=u>=50?1900:2e3),$(u,a,r)}(t)}function p(t){if(t instanceof Date){const e=t.getTime();if(Number.isNaN(e))throw new Error(`Invalid date input: ${String(t)}`);return new Date(e)}if("number"==typeof t){if(!Number.isFinite(t))throw new Error(`Invalid date input: ${String(t)}`);const e=new Date(t);if(Number.isNaN(e.getTime()))throw new Error(`Invalid date input: ${String(t)}`);return e}const e=S(M(t).trim());if(!e)throw new Error(`Invalid date input: ${String(t)}`);return e}function N(t){const e=p(t),n=new Date;return e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate()}function Y(t){const e=p(t),n=new Date;return n.setDate(n.getDate()-1),e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate()}function v(t){const e=p(t),n=new Date;return n.setDate(n.getDate()+1),e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate()}function F(t){const e=p(t);return e.setHours(0,0,0,0),e}function j(t){const e=p(t);return e.setHours(23,59,59,999),e}function k(t,e){const n=p(t);return n.setDate(n.getDate()+e),n}function T(t,e){return k(t,-e)}function B(t,e){return new Date(t,e+1,0).getDate()}function H(t,e){const n=p(t),r=n.getFullYear(),o=n.getMonth()+e,a=r+Math.floor(o/12),u=(o%12+12)%12,s=Math.min(n.getDate(),B(a,u));return n.setFullYear(a,u,s),n}function C(t,e){return H(t,-e)}function I(t,e){const n=p(t),r=n.getFullYear()+e,o=Math.min(n.getDate(),B(r,n.getMonth()));return n.setFullYear(r,n.getMonth(),o),n}function A(t,e){return I(t,-e)}function U(t){const e=p(t);return e.setDate(1),e.setHours(0,0,0,0),e}function x(t){const e=p(t);return e.setMonth(e.getMonth()+1,0),e.setHours(23,59,59,999),e}function E(t){const e=p(t);return e.setMonth(0,1),e.setHours(0,0,0,0),e}function J(t){const e=p(t);return e.setMonth(11,31),e.setHours(23,59,59,999),e}function L(t,e="long"){const n=t-1;if(n<0||n>11)throw new Error(`Invalid month number: ${t}. Must be 1-12.`);return"short"===e?s[n]:u[n]}function O(t){const e=[...h];return function(t){return(e=t+594)%4==0&&e%100!=0||e%400==0;var e}(t)&&(e[10]=31),e}function P(t,e){const n=e?.locale??"en-BD",r=p(t),o=r.getFullYear(),a=r.getMonth(),u=r.getDate(),s=new Date(o,3,14),i=a<3||3===a&&u<14,l=i?o-594:o-593,h=function(t,e){const n=Date.UTC(t.getFullYear(),t.getMonth(),t.getDate()),r=Date.UTC(e.getFullYear(),e.getMonth(),e.getDate());return Math.floor((r-n)/864e5)}(i?new Date(o-1,3,14):s,r)+1,d=O(l);let f=h,m=0;for(let t=0;t<d.length;t++){const e=d[t];if(f<=e){m=t;break}f-=e}const D=m+1;return"bn-BD"===n?{day:y(f),month:c[m],monthIndex:D,year:y(l)}:{day:f,month:g[m],monthIndex:D,year:l}}function W(t,e,n){const r=function(t,e,n){if(!Number.isInteger(t)||!Number.isInteger(e)||!Number.isInteger(n))throw new Error("Invalid Bangla calendar date.");if(e<1||e>12)throw new Error("Invalid Bangla calendar month index. Must be 1-12.");const r=O(n),o=r[e-1];if(t<1||t>o)throw new Error(`Invalid Bangla calendar day. Month ${e} of year ${n} has ${o} days.`);return r}(t,e,n),o=new Date(n+593,3,14);let a=t-1;for(let t=0;t<e-1;t++)a+=r[t];const u=new Date(o);return u.setDate(u.getDate()+a),u}function Z(t){const e=y(t);return 1===t?`${e}লা`:2===t||3===t?`${e}রা`:4===t?`${e}ঠা`:t>=19?`${e}শে`:`${e}ই`}function K(t,e){return"spoken"===(e?.format??"ordinal")?function(t,e="pohela"){switch(t){case 1:return"poyla"===e?"পয়লা":"পহেলা";case 2:return"দোসরা";case 3:return"তেসরা";case 4:return"চৌঠা";default:return Z(t)}}(t,e?.variant):Z(t)}function q(t,e){return"2-digit"===e?String(t).padStart(2,"0"):String(t)}function z(t,e,n){if("bn-BD"===e)return t<12?"পূর্বাহ্ণ":"অপরাহ্ণ";const r=t<12?"AM":"PM";return n?r.toLowerCase():r}function G(t,e){const c=p(t),g=e?.locale??"en-BD",h=e?.month??"short",d=e?.year??"numeric",f=e?.day??"numeric",m=e?.weekday,D=e?.hour,M=e?.minute,b=e?.second,w=void 0!==D||void 0!==M||void 0!==b,$="bn-BD"===g,S=c.getDate(),N=c.getMonth(),Y=c.getFullYear(),v=`${"2-digit"===f?String(S).padStart(2,"0"):String(S)} ${($?"short"===h?s:u:"short"===h?r:n)[N]} ${"2-digit"===d?String(Y).slice(-2):String(Y)}`,F=void 0!==m?`${($?"short"===m?l:i:"short"===m?a:o)[c.getDay()]}, `:"";let j="";if(w){const t=e?.hour12??!1,n=c.getHours(),r=M??(void 0!==b?"2-digit":void 0);j=`${q(t?n%12||12:n,D??"numeric")}${void 0!==r?`:${q(c.getMinutes(),r)}`:""}${void 0!==b?`:${q(c.getSeconds(),b)}`:""}${t?` ${z(n,g,!1)}`:""}`}const k=`${F}${v}${j?`, ${j}`:""}`;return $?y(k):k}function Q(t,e,c){const g=p(t),h=c?.locale??"en-BD",d="bn-BD"===h,f=g.getDate(),m=g.getMonth(),D=g.getFullYear(),M=d?u:n,b=d?s:r,w=d?i:o,$=d?l:a,S=g.getHours(),N=S%12||12,Y={dddd:w[g.getDay()],ddd:$[g.getDay()],MMMM:M[m],MMM:b[m],MM:String(m+1).padStart(2,"0"),M:String(m+1),DD:String(f).padStart(2,"0"),D:String(f),HH:String(S).padStart(2,"0"),H:String(S),hh:String(N).padStart(2,"0"),h:String(N),mm:String(g.getMinutes()).padStart(2,"0"),m:String(g.getMinutes()),ss:String(g.getSeconds()).padStart(2,"0"),s:String(g.getSeconds()),A:z(S,h,!1),a:z(S,h,!0),YYYY:String(D),YY:String(D).slice(-2)},v=e.replace(/dddd|ddd|MMMM|MMM|MM|M|DD|D|YYYY|YY|HH|H|hh|h|mm|m|ss|s|A|a/g,t=>Y[t]);return d?y(v):v}function R(t,e){const n=e?.locale??"en-BD",r=e?.format??"ordinal",o=e?.variant,a=P(t,{locale:"en-BD"});if("bn-BD"===n){const t=a.monthIndex-1,e={format:r};return void 0!==o&&(e.variant=o),`${K(a.day,e)} ${c[t]} ${y(a.year)}`}return`${a.day} ${a.month} ${a.year}`}function V(t,e){const o=p(t),a=e?.digits??"en",i=e?.month??"bn",l=e?.year??"en",c=e?.day??a,g=e?.monthFormat??"long",h=o.getDate(),d=o.getMonth(),f=o.getFullYear(),m="bn"===i?"short"===g?s:u:"short"===g?r:n;return`${"bn"===c?y(h):String(h)} ${m[d]} ${"bn"===l?y(f):String(f)}`}var X={baishakh:1,boishakh:1,boishak:1,boisakh:1,jaishtho:2,jaishtha:2,jaistha:2,joishtho:2,jyoishtho:2,jyoistho:2,jyeshtho:2,ashar:3,asadh:3,asharh:3,srabon:4,shraban:4,shrabon:4,sraban:4,bhadro:5,ashin:6,ashwin:6,ashshin:6,kartik:7,ograyon:8,ograyan:8,ogrohayon:8,ograhayon:8,agrahayan:8,aghrayan:8,pous:9,poush:9,mag:10,magh:10,falgoon:11,falgun:11,choitra:12,chaitra:12,choitro:12},_={"বৈশাখ":1,"জৈষ্ঠ":2,"জ্যৈষ্ঠ":2,"আষাঢ়":3,"আষাঢ়":3,"শ্রাবণ":4,"ভাদ্র":5,"আশ্বিন":6,"কার্তিক":7,"অগ্রহায়ণ":8,"অগ্রহায়ণ":8,"অঘ্রাণ":8,"অগ্রায়ণ":8,"অগ্রায়ণ":8,"পৌষ":9,"পৌস":9,"মাঘ":10,"ফাল্গুন":11,"চৈত্র":12};function tt(t,e){if(t instanceof Date)return Number.isNaN(t.getTime())?null:new Date(t.getTime());if("number"==typeof t){const e=new Date(t);return Number.isNaN(e.getTime())?null:e}const n=M(t).trim();return"bangla"===e?.calendar?function(t){const e=t.match(/^(\S+),?\s+(\S+),?\s+(\d{4})$/);if(!e)return null;const n=function(t){const e={"পহেলা":1,"পয়লা":1,"পয়লা":1,"দোসরা":2,"তেসরা":3,"চৌঠা":4}[t];if(void 0!==e)return e;const n=t.match(/^(\d{1,2})(?:লা|রা|ঠা|ই|শে)$/);if(n)return Number(n[1]);const r=Number(t);return Number.isInteger(r)&&r>=1&&r<=31?r:null}(e[1].replace(/,$/,""));if(null===n)return null;const r=function(t){const e=t.toLowerCase();for(let e=0;e<c.length;e++)if(c[e]===t)return e+1;const n=_[t];if(void 0!==n)return n;for(let t=0;t<g.length;t++)if(g[t].toLowerCase()===e)return t+1;const r=X[e];return void 0!==r?r:-1}(e[2].replace(/,$/,""));if(-1===r)return null;const o=Number(e[3]);try{return W(n,r,o)}catch{return null}}(n):S(n)}var et=1e3,nt=36e5,rt=24*nt,ot=[{threshold:7*rt,singular:"week",plural:"weeks"},{threshold:rt,singular:"day",plural:"days"},{threshold:nt,singular:"hour",plural:"hours"},{threshold:6e4,singular:"minute",plural:"minutes"},{threshold:et,singular:"second",plural:"seconds"}];function at(t,e){return new Date(t,e+1,0).getDate()}function ut(t,e){let n=t.getFullYear()-e.getFullYear();const r=function(t,e){const n=t.getFullYear()+e,r=t.getMonth(),o=Math.min(t.getDate(),at(n,r));return new Date(n,r,o,t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds())}(e,n);return r>t&&(n-=1),n}function st(t,e){let n=12*(t.getFullYear()-e.getFullYear())+(t.getMonth()-e.getMonth());const r=function(t,e){const n=t.getFullYear(),r=t.getMonth()+e,o=n+Math.floor(r/12),a=(r%12+12)%12,u=Math.min(t.getDate(),at(o,a));return new Date(o,a,u,t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds())}(e,n);return r>t&&(n-=1),n}function it(t,e,n,r,o){const a="bn-BD"===o,u=a?y(t):String(t),s=1===t?e:n;return a?r?`${u} ${s} আগে`:`${u} ${s} পরে`:r?`${u} ${s} ago`:`in ${u} ${s}`}function lt(t,e,n){return"bn-BD"===n?"day"===t?e?"গতকাল":"আগামীকাল":"week"===t?e?"গত সপ্তাহে":"আগামী সপ্তাহে":"month"===t?e?"গত মাসে":"আগামী মাসে":e?"গত বছর":"আগামী বছর":"day"===t?e?"yesterday":"tomorrow":"week"===t?e?"last week":"next week":"month"===t?e?"last month":"next month":e?"last year":"next year"}function ct(t,e){const n=p(t),r=e?.locale??"en-BD",o=e?.numeric??"always",a="bn-BD"===r?D:m,u=Date.now()-n.getTime(),s=Math.abs(u),i=u>0,l=new Date,c=n.getFullYear()===l.getFullYear()&&n.getMonth()===l.getMonth()&&n.getDate()===l.getDate(),g=i?l:n,h=i?n:l;if(s<et)return a.justNow;if("auto"===o&&c)return function(t){return"bn-BD"===t?"আজ":"today"}(r);const d=ut(g,h);if(d>=1){if("auto"===o&&1===d){const t=lt("year",i,r);if(null!==t)return t}return it(d,a.year,a.years,i,r)}const f=st(g,h);if(f>=1){if("auto"===o&&1===f){const t=lt("month",i,r);if(null!==t)return t}return it(f,a.month,a.months,i,r)}for(const t of ot)if(s>=t.threshold){const e=Math.floor(s/t.threshold);if("auto"===o&&1===e&&("day"===t.singular||"week"===t.singular)){const e=lt(t.singular,i,r);if(null!==e)return e}return it(e,a[t.singular],a[t.plural],i,r)}return a.justNow}export{c as BANGLA_CALENDAR_MONTHS,g as BANGLA_CALENDAR_MONTHS_EN,h as BANGLA_CALENDAR_MONTH_DAYS,e as BANGLA_DIGITS,u as BANGLA_MONTHS_FULL,s as BANGLA_MONTHS_SHORT,i as BANGLA_WEEKDAYS_FULL,l as BANGLA_WEEKDAYS_SHORT,f as BOISHAKH_START_DAY,d as BOISHAKH_START_MONTH,t as ENGLISH_DIGITS,n as ENGLISH_MONTHS_FULL,r as ENGLISH_MONTHS_SHORT,o as ENGLISH_WEEKDAYS_FULL,a as ENGLISH_WEEKDAYS_SHORT,D as RELATIVE_TIME_BN,m as RELATIVE_TIME_EN,k as addDays,H as addMonths,I as addYears,j as endOfDay,x as endOfMonth,J as endOfYear,Q as format,R as formatBanglaCalendar,K as formatBanglaCalendarDay,G as formatDate,V as formatHybridDate,W as fromBanglaCalendar,ct as fromNow,L as getBanglaMonth,N as isToday,v as isTomorrow,Y as isYesterday,tt as parseDate,F as startOfDay,U as startOfMonth,E as startOfYear,T as subDays,C as subMonths,A as subYears,P as toBanglaCalendar,y as toBanglaDigits,p as toDate,M as toEnglishDigits};
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";var e=require("react"),t=["0","1","2","3","4","5","6","7","8","9"],n=["০","১","২","৩","৪","৫","৬","৭","৮","৯"],r=["January","February","March","April","May","June","July","August","September","October","November","December"],a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],o=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],u=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],i=["জানুয়ারি","ফেব্রুয়ারি","মার্চ","এপ্রিল","মে","জুন","জুলাই","আগস্ট","সেপ্টেম্বর","অক্টোবর","নভেম্বর","ডিসেম্বর"],l=["জানু","ফেব্রু","মার্চ","এপ্রি","মে","জুন","জুলা","আগ","সেপ্টে","অক্টো","নভে","ডিসে"],s=["রবিবার","সোমবার","মঙ্গলবার","বুধবার","বৃহস্পতিবার","শুক্রবার","শনিবার"],c=["রবি","সোম","মঙ্গল","বুধ","বৃহস্পতি","শুক্র","শনি"],d=["বৈশাখ","জ্যৈষ্ঠ","আষাঢ়","শ্রাবণ","ভাদ্র","আশ্বিন","কার্তিক","অগ্রহায়ণ","পৌষ","মাঘ","ফাল্গুন","চৈত্র"],g=["Baishakh","Jaishtho","Asharh","Shrabon","Bhadro","Ashshin","Kartik","Agrahayan","Poush","Magh","Falgun","Chaitra"],h=[31,31,31,31,31,30,30,30,30,30,30,30],m={second:"second",seconds:"seconds",minute:"minute",minutes:"minutes",hour:"hour",hours:"hours",day:"day",days:"days",week:"week",weeks:"weeks",month:"month",months:"months",year:"year",years:"years",ago:"ago",in:"in",justNow:"just now"},f={second:"সেকেন্ড",seconds:"সেকেন্ড",minute:"মিনিট",minutes:"মিনিট",hour:"ঘণ্টা",hours:"ঘণ্টা",day:"দিন",days:"দিন",week:"সপ্তাহ",weeks:"সপ্তাহ",month:"মাস",months:"মাস",year:"বছর",years:"বছর",ago:"আগে",in:"",justNow:"এইমাত্র"};function y(e){return String(e).replace(/\d/g,e=>n[Number(e)]??e)}function b(e){return String(e).replace(/[০-৯]/g,e=>{const r=n.indexOf(e);return r>=0?t[r]??e:e})}var v={jan:0,"jan.":0,january:0,"january,":0,feb:1,"feb.":1,february:1,"february,":1,mar:2,"mar.":2,march:2,"march,":2,apr:3,"apr.":3,april:3,"april,":3,may:4,"may,":4,jun:5,"jun.":5,june:5,"june,":5,jul:6,"jul.":6,july:6,"july,":6,aug:7,"aug.":7,august:7,"august,":7,sep:8,sept:8,"sep.":8,"sept.":8,september:8,"september,":8,oct:9,"oct.":9,october:9,"october,":9,nov:10,"nov.":10,november:10,"november,":10,dec:11,"dec.":11,december:11,"december,":11,"জানুয়ারি":0,"জানুয়ারি":0,"ফেব্রুয়ারি":1,"ফেব্রুয়ারি":1,"মার্চ":2,"এপ্রিল":3,"মে":4,"জুন":5,"জুলাই":6,"আগস্ট":7,"অগাস্ট":7,"সেপ্টেম্বর":8,"সেপ্টেম্বার":8,"অক্টোবর":9,"নভেম্বর":10,"নভেম্বার":10,"ডিসেম্বর":11,"ডিসেম্বার":11,"জানু":0,"ফেব্রু":1,"এপ্রি":3,"জুলা":6,"আগ":7,"সেপ্টে":8,"অক্টো":9,"নভে":10,"ডিসে":11};function w(e){const t=e.trim(),n=t.toLowerCase(),o=v[n];if(void 0!==o)return o;for(let e=0;e<r.length;e++)if(r[e].toLowerCase()===n)return e;for(let e=0;e<a.length;e++)if(a[e].toLowerCase()===n)return e;for(let e=0;e<i.length;e++)if(i[e]===t)return e;for(let e=0;e<l.length;e++)if(l[e]===t)return e;return-1}function $(e,t,n,r=0,a=0,o=0,u=0){const i=new Date(e,t,n,r,a,o,u);return i.getFullYear()!==e||i.getMonth()!==t||i.getDate()!==n||i.getHours()!==r||i.getMinutes()!==a||i.getSeconds()!==o||i.getMilliseconds()!==u?null:i}function D(e){return function(e){const t=e.trim().match(/^(\d{4})([-/.])(\d{1,2})\2(\d{1,2})$/);return t?$(Number(t[1]),Number(t[3])-1,Number(t[4])):null}(e)??function(e){const t=e.trim().match(/^(\d{4})-(\d{2})-(\d{2})(?:[T\s](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:?\d{2})?)$/);if(!t)return null;const n=Number(t[1]),r=Number(t[2]),a=Number(t[3]),o=Number(t[4]??0),u=Number(t[5]??0),i=Number(t[6]??0),l=Number((t[7]??"0").padEnd(3,"0").slice(0,3)),s=t[8];if(void 0===s)return $(n,r-1,a,o,u,i,l);const c=s.match(/^([+-])(\d{2}):?(\d{2})$/),d="Z"===s?0:c?("+"===c[1]?1:-1)*(60*Number(c[2])+Number(c[3])):null;if(null===d)return null;const g=Date.UTC(n,r-1,a,o,u,i,l)-6e4*d,h=new Date(g),m=new Date(g+6e4*d);return m.getUTCFullYear()!==n||m.getUTCMonth()!==r-1||m.getUTCDate()!==a||m.getUTCHours()!==o||m.getUTCMinutes()!==u||m.getUTCSeconds()!==i||m.getUTCMilliseconds()!==l?null:h}(e)??function(e){const t=e.match(/^(\d{1,2})(?:st|nd|rd|th)?(?:\s+|-)(\S+)(?:\s+|-)(\d{2,4})$/);if(!t)return null;const n=Number(t[1]),r=t[2].replace(/,$/,""),a=t[3],o=w(r);if(-1===o)return null;let u=Number(a);return 2===a.length&&(u+=u>=50?1900:2e3),$(u,o,n)}(e)??function(e){const t=e.match(/^(\S+)\s+(\d{1,2})(?:st|nd|rd|th)?(?:,)?\s+(\d{2,4})$/);if(!t)return null;const n=t[1].replace(/,$/,""),r=Number(t[2]),a=t[3],o=w(n);if(-1===o)return null;let u=Number(a);return 2===a.length&&(u+=u>=50?1900:2e3),$(u,o,r)}(e)}function p(e){if(e instanceof Date){const t=e.getTime();if(Number.isNaN(t))throw new Error(`Invalid date input: ${String(e)}`);return new Date(t)}if("number"==typeof e){if(!Number.isFinite(e))throw new Error(`Invalid date input: ${String(e)}`);const t=new Date(e);if(Number.isNaN(t.getTime()))throw new Error(`Invalid date input: ${String(e)}`);return t}const t=D(b(e).trim());if(!t)throw new Error(`Invalid date input: ${String(e)}`);return t}function N(e,t){const n=p(e),r=n.getFullYear(),a=n.getMonth(),o=n.getDate(),u=new Date(r,3,14),i=a<3||3===a&&o<14,l=i?r-594:r-593,s=function(e,t){const n=Date.UTC(e.getFullYear(),e.getMonth(),e.getDate()),r=Date.UTC(t.getFullYear(),t.getMonth(),t.getDate());return Math.floor((r-n)/864e5)}(i?new Date(r-1,3,14):u,n)+1,c=function(e){const t=[...h];return function(e){return(t=e+594)%4==0&&t%100!=0||t%400==0;var t}(e)&&(t[10]=31),t}(l);let d=s,m=0;for(let e=0;e<c.length;e++){const t=c[e];if(d<=t){m=e;break}d-=t}return{day:d,month:g[m],monthIndex:m+1,year:l}}function M(e){const t=y(e);return 1===e?`${t}লা`:2===e||3===e?`${t}রা`:4===e?`${t}ঠা`:e>=19?`${t}শে`:`${t}ই`}function S(e,t){return"spoken"===(t?.format??"ordinal")?function(e,t="pohela"){switch(e){case 1:return"poyla"===t?"পয়লা":"পহেলা";case 2:return"দোসরা";case 3:return"তেসরা";case 4:return"চৌঠা";default:return M(e)}}(e,t?.variant):M(e)}function T(e,t){return"2-digit"===t?String(e).padStart(2,"0"):String(e)}var k=1e3,F=36e5,j=24*F,C=[{threshold:7*j,singular:"week",plural:"weeks"},{threshold:j,singular:"day",plural:"days"},{threshold:F,singular:"hour",plural:"hours"},{threshold:6e4,singular:"minute",plural:"minutes"},{threshold:k,singular:"second",plural:"seconds"}];function Y(e,t){return new Date(e,t+1,0).getDate()}function B(e,t){let n=e.getFullYear()-t.getFullYear();const r=function(e,t){const n=e.getFullYear()+t,r=e.getMonth(),a=Math.min(e.getDate(),Y(n,r));return new Date(n,r,a,e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}(t,n);return r>e&&(n-=1),n}function U(e,t){let n=12*(e.getFullYear()-t.getFullYear())+(e.getMonth()-t.getMonth());const r=function(e,t){const n=e.getFullYear(),r=e.getMonth()+t,a=n+Math.floor(r/12),o=(r%12+12)%12,u=Math.min(e.getDate(),Y(a,o));return new Date(a,o,u,e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}(t,n);return r>e&&(n-=1),n}function x(e,t,n,r,a){const o="bn-BD"===a,u=o?y(e):String(e),i=1===e?t:n;return o?r?`${u} ${i} আগে`:`${u} ${i} পরে`:r?`${u} ${i} ago`:`in ${u} ${i}`}function A(e,t,n){return"bn-BD"===n?"day"===e?t?"গতকাল":"আগামীকাল":"week"===e?t?"গত সপ্তাহে":"আগামী সপ্তাহে":"month"===e?t?"গত মাসে":"আগামী মাসে":t?"গত বছর":"আগামী বছর":"day"===e?t?"yesterday":"tomorrow":"week"===e?t?"last week":"next week":"month"===e?t?"last month":"next month":t?"last year":"next year"}function E(e){return"string"==typeof e&&!/(?:T|\s)\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?(?:Z|[+-]\d{2}:?\d{2})?$/i.test(e.trim())&&null!==function(e){if(e instanceof Date)return Number.isNaN(e.getTime())?null:new Date(e.getTime());if("number"==typeof e){const t=new Date(e);return Number.isNaN(t.getTime())?null:t}return D(b(e).trim())}(e)}function I(e,t){return E(e)?function(e){return`${String(e.getFullYear())}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}(t):t.toISOString()}var J=e.forwardRef(function({value:t,locale:n,month:d,year:g,day:h,weekday:m,hour:f,minute:b,second:v,hour12:w,srLabel:$,"aria-label":D,...N},M){const S=p(t),k=function(e,t){const n=p(e),d=t?.locale??"en-BD",g=t?.month??"short",h=t?.year??"numeric",m=t?.day??"numeric",f=t?.weekday,b=t?.hour,v=t?.minute,w=t?.second,$=void 0!==b||void 0!==v||void 0!==w,D="bn-BD"===d,N=n.getDate(),M=n.getMonth(),S=n.getFullYear(),k=`${"2-digit"===m?String(N).padStart(2,"0"):String(N)} ${(D?"short"===g?l:i:"short"===g?a:r)[M]} ${"2-digit"===h?String(S).slice(-2):String(S)}`,F=void 0!==f?`${(D?"short"===f?c:s:"short"===f?u:o)[n.getDay()]}, `:"";let j="";if($){const e=t?.hour12??!1,r=n.getHours(),a=v??(void 0!==w?"2-digit":void 0),o=T(e?r%12||12:r,b??"numeric"),u=void 0!==a?`:${T(n.getMinutes(),a)}`:"",i=void 0!==w?`:${T(n.getSeconds(),w)}`:"",l=e?` ${function(e,t){if("bn-BD"===t)return e<12?"পূর্বাহ্ণ":"অপরাহ্ণ";const n=e<12?"AM":"PM";return!1?n.toLowerCase():n}(r,d)}`:"";j=`${o}${u}${i}${l}`}const C=`${F}${k}${j?`, ${j}`:""}`;return D?y(C):C}(S,{...void 0!==n&&{locale:n},...void 0!==d&&{month:d},...void 0!==g&&{year:g},...void 0!==h&&{day:h},...void 0!==m&&{weekday:m},...void 0!==f&&{hour:f},...void 0!==b&&{minute:b},...void 0!==v&&{second:v},...void 0!==w&&{hour12:w}}),F=I(t,S),j=$??D??k;return e.createElement("time",{...N,ref:M,dateTime:F,"aria-label":j},k)});J.displayName="Tarikh";var L=e.forwardRef(function({value:t,locale:n,numeric:r,srLabel:a,"aria-label":o,...u},i){const l=p(t),s={...void 0!==n&&{locale:n},...void 0!==r&&{numeric:r}},c=function(e,t){const n=p(e),r=t?.locale??"en-BD",a=t?.numeric??"always",o="bn-BD"===r?f:m,u=Date.now()-n.getTime(),i=Math.abs(u),l=u>0,s=new Date,c=n.getFullYear()===s.getFullYear()&&n.getMonth()===s.getMonth()&&n.getDate()===s.getDate(),d=l?s:n,g=l?n:s;if(i<k)return o.justNow;if("auto"===a&&c)return function(e){return"bn-BD"===e?"আজ":"today"}(r);const h=B(d,g);if(h>=1){if("auto"===a&&1===h){const e=A("year",l,r);if(null!==e)return e}return x(h,o.year,o.years,l,r)}const y=U(d,g);if(y>=1){if("auto"===a&&1===y){const e=A("month",l,r);if(null!==e)return e}return x(y,o.month,o.months,l,r)}for(const e of C)if(i>=e.threshold){const t=Math.floor(i/e.threshold);if("auto"===a&&1===t&&("day"===e.singular||"week"===e.singular)){const t=A(e.singular,l,r);if(null!==t)return t}return x(t,o[e.singular],o[e.plural],l,r)}return o.justNow}(l,Object.keys(s).length>0?s:void 0),d=I(t,l),g=a??o??c;return e.createElement("time",{...u,ref:i,dateTime:d,"aria-label":g},c)});L.displayName="RelativeTime";var O=e.forwardRef(function({value:t,locale:n,format:r,variant:a,srLabel:o,"aria-label":u,...i},l){const s=p(t),c={...void 0!==n&&{locale:n},...void 0!==r&&{format:r},...void 0!==a&&{variant:a}},g=function(e,t){const n=t?.locale??"en-BD",r=t?.format??"ordinal",a=t?.variant,o=N(e);if("bn-BD"===n){const e=o.monthIndex-1,t={format:r};return void 0!==a&&(t.variant=a),`${S(o.day,t)} ${d[e]} ${y(o.year)}`}return`${o.day} ${o.month} ${o.year}`}(s,Object.keys(c).length>0?c:void 0),h=I(t,s),m=o??u??g;return e.createElement("time",{...i,ref:l,dateTime:h,"aria-label":m},g)});O.displayName="BanglaDate",exports.BanglaDate=O,exports.RelativeTime=L,exports.Tarikh=J;
|
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
|
|
4
|
+
type Locale = "en-BD" | "bn-BD";
|
|
5
|
+
type MonthFormat = "short" | "long";
|
|
6
|
+
type YearFormat = "numeric" | "2-digit";
|
|
7
|
+
type DayFormat = "numeric" | "2-digit";
|
|
8
|
+
type WeekdayFormat = "short" | "long";
|
|
9
|
+
type TimeFormat = "numeric" | "2-digit";
|
|
10
|
+
type DateInput = Date | string | number;
|
|
11
|
+
interface DateFormatOptions {
|
|
12
|
+
locale?: Locale;
|
|
13
|
+
month?: MonthFormat;
|
|
14
|
+
year?: YearFormat;
|
|
15
|
+
day?: DayFormat;
|
|
16
|
+
weekday?: WeekdayFormat;
|
|
17
|
+
hour?: TimeFormat;
|
|
18
|
+
minute?: TimeFormat;
|
|
19
|
+
second?: TimeFormat;
|
|
20
|
+
hour12?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface RelativeTimeOptions {
|
|
23
|
+
locale?: Locale;
|
|
24
|
+
numeric?: "always" | "auto";
|
|
25
|
+
}
|
|
26
|
+
type BanglaCalendarDayFormat = "ordinal" | "spoken";
|
|
27
|
+
type BanglaCalendarDaySpokenVariant = "pohela" | "poyla";
|
|
28
|
+
|
|
29
|
+
interface TarikhProps extends Omit<ComponentPropsWithoutRef<"time">, "children">, Omit<DateFormatOptions, "locale"> {
|
|
30
|
+
value: DateInput;
|
|
31
|
+
locale?: Locale;
|
|
32
|
+
srLabel?: string;
|
|
33
|
+
}
|
|
34
|
+
interface RelativeTimeProps extends Omit<ComponentPropsWithoutRef<"time">, "children"> {
|
|
35
|
+
value: DateInput;
|
|
36
|
+
locale?: Locale;
|
|
37
|
+
numeric?: RelativeTimeOptions["numeric"];
|
|
38
|
+
srLabel?: string;
|
|
39
|
+
}
|
|
40
|
+
interface BanglaDateProps extends Omit<ComponentPropsWithoutRef<"time">, "children"> {
|
|
41
|
+
value: DateInput;
|
|
42
|
+
locale?: Locale;
|
|
43
|
+
format?: BanglaCalendarDayFormat;
|
|
44
|
+
variant?: BanglaCalendarDaySpokenVariant;
|
|
45
|
+
srLabel?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare const Tarikh: react.ForwardRefExoticComponent<TarikhProps & react.RefAttributes<HTMLTimeElement>>;
|
|
49
|
+
declare const RelativeTime: react.ForwardRefExoticComponent<RelativeTimeProps & react.RefAttributes<HTMLTimeElement>>;
|
|
50
|
+
declare const BanglaDate: react.ForwardRefExoticComponent<BanglaDateProps & react.RefAttributes<HTMLTimeElement>>;
|
|
51
|
+
|
|
52
|
+
export { BanglaDate, type BanglaDateProps, RelativeTime, type RelativeTimeProps, Tarikh, type TarikhProps };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
|
|
4
|
+
type Locale = "en-BD" | "bn-BD";
|
|
5
|
+
type MonthFormat = "short" | "long";
|
|
6
|
+
type YearFormat = "numeric" | "2-digit";
|
|
7
|
+
type DayFormat = "numeric" | "2-digit";
|
|
8
|
+
type WeekdayFormat = "short" | "long";
|
|
9
|
+
type TimeFormat = "numeric" | "2-digit";
|
|
10
|
+
type DateInput = Date | string | number;
|
|
11
|
+
interface DateFormatOptions {
|
|
12
|
+
locale?: Locale;
|
|
13
|
+
month?: MonthFormat;
|
|
14
|
+
year?: YearFormat;
|
|
15
|
+
day?: DayFormat;
|
|
16
|
+
weekday?: WeekdayFormat;
|
|
17
|
+
hour?: TimeFormat;
|
|
18
|
+
minute?: TimeFormat;
|
|
19
|
+
second?: TimeFormat;
|
|
20
|
+
hour12?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface RelativeTimeOptions {
|
|
23
|
+
locale?: Locale;
|
|
24
|
+
numeric?: "always" | "auto";
|
|
25
|
+
}
|
|
26
|
+
type BanglaCalendarDayFormat = "ordinal" | "spoken";
|
|
27
|
+
type BanglaCalendarDaySpokenVariant = "pohela" | "poyla";
|
|
28
|
+
|
|
29
|
+
interface TarikhProps extends Omit<ComponentPropsWithoutRef<"time">, "children">, Omit<DateFormatOptions, "locale"> {
|
|
30
|
+
value: DateInput;
|
|
31
|
+
locale?: Locale;
|
|
32
|
+
srLabel?: string;
|
|
33
|
+
}
|
|
34
|
+
interface RelativeTimeProps extends Omit<ComponentPropsWithoutRef<"time">, "children"> {
|
|
35
|
+
value: DateInput;
|
|
36
|
+
locale?: Locale;
|
|
37
|
+
numeric?: RelativeTimeOptions["numeric"];
|
|
38
|
+
srLabel?: string;
|
|
39
|
+
}
|
|
40
|
+
interface BanglaDateProps extends Omit<ComponentPropsWithoutRef<"time">, "children"> {
|
|
41
|
+
value: DateInput;
|
|
42
|
+
locale?: Locale;
|
|
43
|
+
format?: BanglaCalendarDayFormat;
|
|
44
|
+
variant?: BanglaCalendarDaySpokenVariant;
|
|
45
|
+
srLabel?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare const Tarikh: react.ForwardRefExoticComponent<TarikhProps & react.RefAttributes<HTMLTimeElement>>;
|
|
49
|
+
declare const RelativeTime: react.ForwardRefExoticComponent<RelativeTimeProps & react.RefAttributes<HTMLTimeElement>>;
|
|
50
|
+
declare const BanglaDate: react.ForwardRefExoticComponent<BanglaDateProps & react.RefAttributes<HTMLTimeElement>>;
|
|
51
|
+
|
|
52
|
+
export { BanglaDate, type BanglaDateProps, RelativeTime, type RelativeTimeProps, Tarikh, type TarikhProps };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{forwardRef as e,createElement as t}from"react";var n=["0","1","2","3","4","5","6","7","8","9"],r=["০","১","২","৩","৪","৫","৬","৭","৮","৯"],a=["January","February","March","April","May","June","July","August","September","October","November","December"],o=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],u=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],i=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],l=["জানুয়ারি","ফেব্রুয়ারি","মার্চ","এপ্রিল","মে","জুন","জুলাই","আগস্ট","সেপ্টেম্বর","অক্টোবর","নভেম্বর","ডিসেম্বর"],s=["জানু","ফেব্রু","মার্চ","এপ্রি","মে","জুন","জুলা","আগ","সেপ্টে","অক্টো","নভে","ডিসে"],c=["রবিবার","সোমবার","মঙ্গলবার","বুধবার","বৃহস্পতিবার","শুক্রবার","শনিবার"],d=["রবি","সোম","মঙ্গল","বুধ","বৃহস্পতি","শুক্র","শনি"],g=["বৈশাখ","জ্যৈষ্ঠ","আষাঢ়","শ্রাবণ","ভাদ্র","আশ্বিন","কার্তিক","অগ্রহায়ণ","পৌষ","মাঘ","ফাল্গুন","চৈত্র"],h=["Baishakh","Jaishtho","Asharh","Shrabon","Bhadro","Ashshin","Kartik","Agrahayan","Poush","Magh","Falgun","Chaitra"],m=[31,31,31,31,31,30,30,30,30,30,30,30],f={second:"second",seconds:"seconds",minute:"minute",minutes:"minutes",hour:"hour",hours:"hours",day:"day",days:"days",week:"week",weeks:"weeks",month:"month",months:"months",year:"year",years:"years",ago:"ago",in:"in",justNow:"just now"},y={second:"সেকেন্ড",seconds:"সেকেন্ড",minute:"মিনিট",minutes:"মিনিট",hour:"ঘণ্টা",hours:"ঘণ্টা",day:"দিন",days:"দিন",week:"সপ্তাহ",weeks:"সপ্তাহ",month:"মাস",months:"মাস",year:"বছর",years:"বছর",ago:"আগে",in:"",justNow:"এইমাত্র"};function b(e){return String(e).replace(/\d/g,e=>r[Number(e)]??e)}function v(e){return String(e).replace(/[০-৯]/g,e=>{const t=r.indexOf(e);return t>=0?n[t]??e:e})}var w={jan:0,"jan.":0,january:0,"january,":0,feb:1,"feb.":1,february:1,"february,":1,mar:2,"mar.":2,march:2,"march,":2,apr:3,"apr.":3,april:3,"april,":3,may:4,"may,":4,jun:5,"jun.":5,june:5,"june,":5,jul:6,"jul.":6,july:6,"july,":6,aug:7,"aug.":7,august:7,"august,":7,sep:8,sept:8,"sep.":8,"sept.":8,september:8,"september,":8,oct:9,"oct.":9,october:9,"october,":9,nov:10,"nov.":10,november:10,"november,":10,dec:11,"dec.":11,december:11,"december,":11,"জানুয়ারি":0,"জানুয়ারি":0,"ফেব্রুয়ারি":1,"ফেব্রুয়ারি":1,"মার্চ":2,"এপ্রিল":3,"মে":4,"জুন":5,"জুলাই":6,"আগস্ট":7,"অগাস্ট":7,"সেপ্টেম্বর":8,"সেপ্টেম্বার":8,"অক্টোবর":9,"নভেম্বর":10,"নভেম্বার":10,"ডিসেম্বর":11,"ডিসেম্বার":11,"জানু":0,"ফেব্রু":1,"এপ্রি":3,"জুলা":6,"আগ":7,"সেপ্টে":8,"অক্টো":9,"নভে":10,"ডিসে":11};function $(e){const t=e.trim(),n=t.toLowerCase(),r=w[n];if(void 0!==r)return r;for(let e=0;e<a.length;e++)if(a[e].toLowerCase()===n)return e;for(let e=0;e<o.length;e++)if(o[e].toLowerCase()===n)return e;for(let e=0;e<l.length;e++)if(l[e]===t)return e;for(let e=0;e<s.length;e++)if(s[e]===t)return e;return-1}function D(e,t,n,r=0,a=0,o=0,u=0){const i=new Date(e,t,n,r,a,o,u);return i.getFullYear()!==e||i.getMonth()!==t||i.getDate()!==n||i.getHours()!==r||i.getMinutes()!==a||i.getSeconds()!==o||i.getMilliseconds()!==u?null:i}function p(e){return function(e){const t=e.trim().match(/^(\d{4})([-/.])(\d{1,2})\2(\d{1,2})$/);return t?D(Number(t[1]),Number(t[3])-1,Number(t[4])):null}(e)??function(e){const t=e.trim().match(/^(\d{4})-(\d{2})-(\d{2})(?:[T\s](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:?\d{2})?)$/);if(!t)return null;const n=Number(t[1]),r=Number(t[2]),a=Number(t[3]),o=Number(t[4]??0),u=Number(t[5]??0),i=Number(t[6]??0),l=Number((t[7]??"0").padEnd(3,"0").slice(0,3)),s=t[8];if(void 0===s)return D(n,r-1,a,o,u,i,l);const c=s.match(/^([+-])(\d{2}):?(\d{2})$/),d="Z"===s?0:c?("+"===c[1]?1:-1)*(60*Number(c[2])+Number(c[3])):null;if(null===d)return null;const g=Date.UTC(n,r-1,a,o,u,i,l)-6e4*d,h=new Date(g),m=new Date(g+6e4*d);return m.getUTCFullYear()!==n||m.getUTCMonth()!==r-1||m.getUTCDate()!==a||m.getUTCHours()!==o||m.getUTCMinutes()!==u||m.getUTCSeconds()!==i||m.getUTCMilliseconds()!==l?null:h}(e)??function(e){const t=e.match(/^(\d{1,2})(?:st|nd|rd|th)?(?:\s+|-)(\S+)(?:\s+|-)(\d{2,4})$/);if(!t)return null;const n=Number(t[1]),r=t[2].replace(/,$/,""),a=t[3],o=$(r);if(-1===o)return null;let u=Number(a);return 2===a.length&&(u+=u>=50?1900:2e3),D(u,o,n)}(e)??function(e){const t=e.match(/^(\S+)\s+(\d{1,2})(?:st|nd|rd|th)?(?:,)?\s+(\d{2,4})$/);if(!t)return null;const n=t[1].replace(/,$/,""),r=Number(t[2]),a=t[3],o=$(n);if(-1===o)return null;let u=Number(a);return 2===a.length&&(u+=u>=50?1900:2e3),D(u,o,r)}(e)}function N(e){if(e instanceof Date){const t=e.getTime();if(Number.isNaN(t))throw new Error(`Invalid date input: ${String(e)}`);return new Date(t)}if("number"==typeof e){if(!Number.isFinite(e))throw new Error(`Invalid date input: ${String(e)}`);const t=new Date(e);if(Number.isNaN(t.getTime()))throw new Error(`Invalid date input: ${String(e)}`);return t}const t=p(v(e).trim());if(!t)throw new Error(`Invalid date input: ${String(e)}`);return t}function M(e,t){const n=N(e),r=n.getFullYear(),a=n.getMonth(),o=n.getDate(),u=new Date(r,3,14),i=a<3||3===a&&o<14,l=i?r-594:r-593,s=function(e,t){const n=Date.UTC(e.getFullYear(),e.getMonth(),e.getDate()),r=Date.UTC(t.getFullYear(),t.getMonth(),t.getDate());return Math.floor((r-n)/864e5)}(i?new Date(r-1,3,14):u,n)+1,c=function(e){const t=[...m];return function(e){return(t=e+594)%4==0&&t%100!=0||t%400==0;var t}(e)&&(t[10]=31),t}(l);let d=s,g=0;for(let e=0;e<c.length;e++){const t=c[e];if(d<=t){g=e;break}d-=t}return{day:d,month:h[g],monthIndex:g+1,year:l}}function S(e){const t=b(e);return 1===e?`${t}লা`:2===e||3===e?`${t}রা`:4===e?`${t}ঠা`:e>=19?`${t}শে`:`${t}ই`}function T(e,t){return"spoken"===(t?.format??"ordinal")?function(e,t="pohela"){switch(e){case 1:return"poyla"===t?"পয়লা":"পহেলা";case 2:return"দোসরা";case 3:return"তেসরা";case 4:return"চৌঠা";default:return S(e)}}(e,t?.variant):S(e)}function k(e,t){return"2-digit"===t?String(e).padStart(2,"0"):String(e)}var F=1e3,j=36e5,C=24*j,Y=[{threshold:7*C,singular:"week",plural:"weeks"},{threshold:C,singular:"day",plural:"days"},{threshold:j,singular:"hour",plural:"hours"},{threshold:6e4,singular:"minute",plural:"minutes"},{threshold:F,singular:"second",plural:"seconds"}];function B(e,t){return new Date(e,t+1,0).getDate()}function U(e,t){let n=e.getFullYear()-t.getFullYear();const r=function(e,t){const n=e.getFullYear()+t,r=e.getMonth(),a=Math.min(e.getDate(),B(n,r));return new Date(n,r,a,e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}(t,n);return r>e&&(n-=1),n}function A(e,t){let n=12*(e.getFullYear()-t.getFullYear())+(e.getMonth()-t.getMonth());const r=function(e,t){const n=e.getFullYear(),r=e.getMonth()+t,a=n+Math.floor(r/12),o=(r%12+12)%12,u=Math.min(e.getDate(),B(a,o));return new Date(a,o,u,e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}(t,n);return r>e&&(n-=1),n}function x(e,t,n,r,a){const o="bn-BD"===a,u=o?b(e):String(e),i=1===e?t:n;return o?r?`${u} ${i} আগে`:`${u} ${i} পরে`:r?`${u} ${i} ago`:`in ${u} ${i}`}function I(e,t,n){return"bn-BD"===n?"day"===e?t?"গতকাল":"আগামীকাল":"week"===e?t?"গত সপ্তাহে":"আগামী সপ্তাহে":"month"===e?t?"গত মাসে":"আগামী মাসে":t?"গত বছর":"আগামী বছর":"day"===e?t?"yesterday":"tomorrow":"week"===e?t?"last week":"next week":"month"===e?t?"last month":"next month":t?"last year":"next year"}function J(e){return"string"==typeof e&&!/(?:T|\s)\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?(?:Z|[+-]\d{2}:?\d{2})?$/i.test(e.trim())&&null!==function(e){if(e instanceof Date)return Number.isNaN(e.getTime())?null:new Date(e.getTime());if("number"==typeof e){const t=new Date(e);return Number.isNaN(t.getTime())?null:t}return p(v(e).trim())}(e)}function L(e,t){return J(e)?function(e){return`${String(e.getFullYear())}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}(t):t.toISOString()}var O=e(function({value:e,locale:n,month:r,year:g,day:h,weekday:m,hour:f,minute:y,second:v,hour12:w,srLabel:$,"aria-label":D,...p},M){const S=N(e),T=function(e,t){const n=N(e),r=t?.locale??"en-BD",g=t?.month??"short",h=t?.year??"numeric",m=t?.day??"numeric",f=t?.weekday,y=t?.hour,v=t?.minute,w=t?.second,$=void 0!==y||void 0!==v||void 0!==w,D="bn-BD"===r,p=n.getDate(),M=n.getMonth(),S=n.getFullYear(),T=`${"2-digit"===m?String(p).padStart(2,"0"):String(p)} ${(D?"short"===g?s:l:"short"===g?o:a)[M]} ${"2-digit"===h?String(S).slice(-2):String(S)}`,F=void 0!==f?`${(D?"short"===f?d:c:"short"===f?i:u)[n.getDay()]}, `:"";let j="";if($){const e=t?.hour12??!1,a=n.getHours(),o=v??(void 0!==w?"2-digit":void 0),u=k(e?a%12||12:a,y??"numeric"),i=void 0!==o?`:${k(n.getMinutes(),o)}`:"",l=void 0!==w?`:${k(n.getSeconds(),w)}`:"",s=e?` ${function(e,t){if("bn-BD"===t)return e<12?"পূর্বাহ্ণ":"অপরাহ্ণ";const n=e<12?"AM":"PM";return!1?n.toLowerCase():n}(a,r)}`:"";j=`${u}${i}${l}${s}`}const C=`${F}${T}${j?`, ${j}`:""}`;return D?b(C):C}(S,{...void 0!==n&&{locale:n},...void 0!==r&&{month:r},...void 0!==g&&{year:g},...void 0!==h&&{day:h},...void 0!==m&&{weekday:m},...void 0!==f&&{hour:f},...void 0!==y&&{minute:y},...void 0!==v&&{second:v},...void 0!==w&&{hour12:w}}),F=L(e,S);return t("time",{...p,ref:M,dateTime:F,"aria-label":$??D??T},T)});O.displayName="Tarikh";var E=e(function({value:e,locale:n,numeric:r,srLabel:a,"aria-label":o,...u},i){const l=N(e),s={...void 0!==n&&{locale:n},...void 0!==r&&{numeric:r}},c=function(e,t){const n=N(e),r=t?.locale??"en-BD",a=t?.numeric??"always",o="bn-BD"===r?y:f,u=Date.now()-n.getTime(),i=Math.abs(u),l=u>0,s=new Date,c=n.getFullYear()===s.getFullYear()&&n.getMonth()===s.getMonth()&&n.getDate()===s.getDate(),d=l?s:n,g=l?n:s;if(i<F)return o.justNow;if("auto"===a&&c)return function(e){return"bn-BD"===e?"আজ":"today"}(r);const h=U(d,g);if(h>=1){if("auto"===a&&1===h){const e=I("year",l,r);if(null!==e)return e}return x(h,o.year,o.years,l,r)}const m=A(d,g);if(m>=1){if("auto"===a&&1===m){const e=I("month",l,r);if(null!==e)return e}return x(m,o.month,o.months,l,r)}for(const e of Y)if(i>=e.threshold){const t=Math.floor(i/e.threshold);if("auto"===a&&1===t&&("day"===e.singular||"week"===e.singular)){const t=I(e.singular,l,r);if(null!==t)return t}return x(t,o[e.singular],o[e.plural],l,r)}return o.justNow}(l,Object.keys(s).length>0?s:void 0),d=L(e,l);return t("time",{...u,ref:i,dateTime:d,"aria-label":a??o??c},c)});E.displayName="RelativeTime";var H=e(function({value:e,locale:n,format:r,variant:a,srLabel:o,"aria-label":u,...i},l){const s=N(e),c={...void 0!==n&&{locale:n},...void 0!==r&&{format:r},...void 0!==a&&{variant:a}},d=function(e,t){const n=t?.locale??"en-BD",r=t?.format??"ordinal",a=t?.variant,o=M(e);if("bn-BD"===n){const e=o.monthIndex-1,t={format:r};return void 0!==a&&(t.variant=a),`${T(o.day,t)} ${g[e]} ${b(o.year)}`}return`${o.day} ${o.month} ${o.year}`}(s,Object.keys(c).length>0?c:void 0),h=L(e,s);return t("time",{...i,ref:l,dateTime:h,"aria-label":o??u??d},d)});H.displayName="BanglaDate";export{H as BanglaDate,E as RelativeTime,O as Tarikh};
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coreify/tarikh",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A modern Bangladesh-first date toolkit for formatting, Bangla calendar, and localization in JavaScript, TypeScript, and React apps.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./react": {
|
|
17
|
+
"types": "./dist/react.d.ts",
|
|
18
|
+
"import": "./dist/react.js",
|
|
19
|
+
"require": "./dist/react.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup",
|
|
33
|
+
"build:watch": "tsup --watch",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"lint": "eslint .",
|
|
36
|
+
"ci": "npm run lint && npm run typecheck && npm test",
|
|
37
|
+
"test": "npm run build && vitest run",
|
|
38
|
+
"test:unit": "vitest run",
|
|
39
|
+
"test:watch": "vitest",
|
|
40
|
+
"format": "prettier --write \"**/*.{ts,tsx,js,json,md}\""
|
|
41
|
+
},
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"author": "Coreify",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/coreify/tarikh.git"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://tarikh.js.org",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/coreify/tarikh/issues"
|
|
51
|
+
},
|
|
52
|
+
"prepack": "npm run build",
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"react": ">=18"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"react": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@eslint/js": "^10.0.1",
|
|
66
|
+
"@types/node": "^25.5.0",
|
|
67
|
+
"@types/react": "^19.2.14",
|
|
68
|
+
"@types/react-dom": "^19.2.3",
|
|
69
|
+
"eslint": "^10.1.0",
|
|
70
|
+
"globals": "^17.4.0",
|
|
71
|
+
"prettier": "^3.8.1",
|
|
72
|
+
"react": "^19.2.4",
|
|
73
|
+
"react-dom": "^19.2.4",
|
|
74
|
+
"terser": "^5.46.1",
|
|
75
|
+
"tsup": "^8.5.1",
|
|
76
|
+
"typescript": "^5.9.3",
|
|
77
|
+
"typescript-eslint": "^8.58.0",
|
|
78
|
+
"vitest": "^4.1.2"
|
|
79
|
+
},
|
|
80
|
+
"keywords": [
|
|
81
|
+
"tarikh",
|
|
82
|
+
"date",
|
|
83
|
+
"bangla",
|
|
84
|
+
"bengali",
|
|
85
|
+
"bangladesh",
|
|
86
|
+
"calendar",
|
|
87
|
+
"formatting",
|
|
88
|
+
"localization",
|
|
89
|
+
"react",
|
|
90
|
+
"typescript"
|
|
91
|
+
]
|
|
92
|
+
}
|