nhb-toolbox 4.28.40 → 4.28.50
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/CHANGELOG.md +13 -1
- package/README.md +31 -0
- package/dist/cjs/date/BanglaCalendar.js +228 -0
- package/dist/cjs/date/Chronos.js +21 -16
- package/dist/cjs/date/chronos-fn.js +17 -15
- package/dist/cjs/date/constants.js +145 -3
- package/dist/cjs/date/helpers.js +91 -28
- package/dist/cjs/date/plugins/banglaPlugin.js +101 -0
- package/dist/cjs/date/plugins/roundPlugin.js +2 -2
- package/dist/cjs/date/utils.js +8 -2
- package/dist/cjs/index.js +21 -13
- package/dist/cjs/number/constants.js +13 -9
- package/dist/cjs/number/convert.js +33 -0
- package/dist/dts/date/BanglaCalendar.d.ts +529 -0
- package/dist/dts/date/Chronos.d.ts +12 -12
- package/dist/dts/date/chronos-fn.d.ts +5 -10
- package/dist/dts/date/chronos-statics.d.ts +3 -5
- package/dist/dts/date/constants.d.ts +122 -3
- package/dist/dts/date/helpers.d.ts +25 -3
- package/dist/dts/date/plugins/banglaPlugin.d.ts +221 -0
- package/dist/dts/date/types.d.ts +91 -23
- package/dist/dts/date/utils.d.ts +22 -1
- package/dist/dts/hash/helpers.d.ts +1 -1
- package/dist/dts/hash/utils.d.ts +1 -6
- package/dist/dts/http-status/HttpStatus.d.ts +0 -4
- package/dist/dts/index.d.ts +5 -4
- package/dist/dts/number/basics.d.ts +0 -4
- package/dist/dts/number/constants.d.ts +15 -6
- package/dist/dts/number/convert.d.ts +46 -2
- package/dist/dts/number/types.d.ts +15 -13
- package/dist/dts/object/types.d.ts +0 -2
- package/dist/dts/utils/types.d.ts +4 -10
- package/dist/esm/date/BanglaCalendar.js +223 -0
- package/dist/esm/date/Chronos.js +18 -18
- package/dist/esm/date/chronos-fn.js +12 -14
- package/dist/esm/date/constants.js +144 -2
- package/dist/esm/date/helpers.js +82 -29
- package/dist/esm/date/plugins/banglaPlugin.js +97 -0
- package/dist/esm/date/plugins/roundPlugin.js +3 -3
- package/dist/esm/date/utils.js +8 -3
- package/dist/esm/index.js +5 -4
- package/dist/esm/number/constants.js +12 -8
- package/dist/esm/number/convert.js +32 -1
- package/package.json +45 -7
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
All notable changes to the package will be documented here.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## [4.28.50] - 2025-12-24
|
|
8
|
+
|
|
9
|
+
### ✨ New Class, Chronos Plugin, and Utilities
|
|
10
|
+
|
|
11
|
+
- **Added** a *new* class: `BanglaCalendar` for creating, manipulating, and converting dates between the Bangla and Gregorian calendar systems.
|
|
12
|
+
- **Introduced** a *new* `Chronos` *plugin*: `banglaPlugin`, enabling Bangla calendar support within `Chronos`.
|
|
13
|
+
- **Added** *new* numeric conversion utilities: `banglaToDigit` and `digitToBangla`, for working with Bangla numerals.
|
|
14
|
+
- **Added** a *new* date/time utility: `formatTimePart` for formatting a string that only has the time component.
|
|
15
|
+
- **Fixed** minor *issues* in `Chronos` and **improved** *type system* for date and number related utilities.
|
|
16
|
+
|
|
17
|
+
## [4.28.44] - 2025-12-19
|
|
18
|
+
|
|
19
|
+
- **Updated** `DateTimeFormatOptions` with *improved type system* and **removed** *unsupported* **locales/currencies** from *constants* and *types*.
|
|
8
20
|
|
|
9
21
|
## [4.28.40] - 2025-12-15
|
|
10
22
|
|
package/README.md
CHANGED
|
@@ -226,6 +226,37 @@ chronos('2025-01-01').addDays(3).format('YYYY-MM-DD'); // "2025-01-04"
|
|
|
226
226
|
|
|
227
227
|
---
|
|
228
228
|
|
|
229
|
+
### 🕰️ Bangla Calendar (Revised: 1966 & 2019)
|
|
230
|
+
|
|
231
|
+
**`BanglaCalendar`** - The class to create, manipulate, and convert dates between the Bangla and Gregorian calendar systems.
|
|
232
|
+
|
|
233
|
+
> It supports two calendar variants: `'revised-2019'` (default) and `'revised-1966'`.
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
// Create from current date
|
|
237
|
+
const today = new BanglaCalendar();
|
|
238
|
+
|
|
239
|
+
// Create from Bangla date string (Bangla digit)
|
|
240
|
+
const date0 = new BanglaCalendar('১৪৩২-১১-০৮');
|
|
241
|
+
|
|
242
|
+
// Create from Gregorian date
|
|
243
|
+
const date1 = new BanglaCalendar('2023-04-14'); // Latin digit
|
|
244
|
+
const date2 = new BanglaCalendar(new Date('2023-04-14')); // Date object
|
|
245
|
+
|
|
246
|
+
// Create with specific Bangla date using Latin digits
|
|
247
|
+
const date3 = new BanglaCalendar(1430, 1, 1);
|
|
248
|
+
|
|
249
|
+
// Create with specific Bangla date using Bangla digits
|
|
250
|
+
const date4 = new BanglaCalendar('১৪৩০', '১', '১');
|
|
251
|
+
|
|
252
|
+
// Create with specific variant
|
|
253
|
+
const date5 = new BanglaCalendar('১৪৩০', '১', '১', { variant: 'revised-1966' });
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
[Documentation →](https://toolbox.nazmul-nhb.dev/docs/classes/BanglaCalendar)
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
229
260
|
### 🎨 Professional Color Manipulation
|
|
230
261
|
|
|
231
262
|
**`Color`** - Convert between color formats, generate palettes, check accessibility contrast, and perform advanced color math with perfect type safety.
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Bongabdo = exports.BnCalendar = exports.BanglaCalendar = void 0;
|
|
4
|
+
const non_primitives_1 = require("../guards/non-primitives");
|
|
5
|
+
const primitives_1 = require("../guards/primitives");
|
|
6
|
+
const specials_1 = require("../guards/specials");
|
|
7
|
+
const convert_1 = require("../number/convert");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
const helpers_1 = require("./helpers");
|
|
10
|
+
class BanglaCalendar {
|
|
11
|
+
variant;
|
|
12
|
+
year;
|
|
13
|
+
month;
|
|
14
|
+
date;
|
|
15
|
+
gregorian;
|
|
16
|
+
weekDay;
|
|
17
|
+
isoWeekDay;
|
|
18
|
+
constructor(dateBnYrOrCfg, bnMonthOrCfg, bnDateOrCfg, config) {
|
|
19
|
+
this.variant = this.#processVariants(dateBnYrOrCfg, bnMonthOrCfg, bnDateOrCfg, config);
|
|
20
|
+
let date = dateBnYrOrCfg instanceof Date ? dateBnYrOrCfg : (new Date(((0, specials_1.isDateString)(dateBnYrOrCfg) &&
|
|
21
|
+
!BanglaCalendar.isBanglaDateString(dateBnYrOrCfg)) ?
|
|
22
|
+
dateBnYrOrCfg
|
|
23
|
+
: (0, primitives_1.isNumber)(dateBnYrOrCfg) && !BanglaCalendar.isBanglaYearEn(dateBnYrOrCfg) ?
|
|
24
|
+
dateBnYrOrCfg
|
|
25
|
+
: Date.now()));
|
|
26
|
+
if (isNaN(date.getTime())) {
|
|
27
|
+
date = new Date();
|
|
28
|
+
}
|
|
29
|
+
const { year, month, monthDate } = this.#processDate(date);
|
|
30
|
+
let bnYear = BanglaCalendar.isBanglaYear(dateBnYrOrCfg) ? (0, convert_1.banglaToDigit)(dateBnYrOrCfg)
|
|
31
|
+
: (0, primitives_1.isNumber)(dateBnYrOrCfg) && BanglaCalendar.isBanglaYearEn(dateBnYrOrCfg) ?
|
|
32
|
+
dateBnYrOrCfg
|
|
33
|
+
: year;
|
|
34
|
+
let bnMonth = BanglaCalendar.isBanglaMonth(bnMonthOrCfg) ? (0, convert_1.banglaToDigit)(bnMonthOrCfg)
|
|
35
|
+
: BanglaCalendar.isBanglaMonthEn(bnMonthOrCfg) ? bnMonthOrCfg
|
|
36
|
+
: month;
|
|
37
|
+
let bnDate = BanglaCalendar.isBanglaDate(bnDateOrCfg) ? (0, convert_1.banglaToDigit)(bnDateOrCfg)
|
|
38
|
+
: BanglaCalendar.isBanglaDateEn(bnDateOrCfg) ? bnDateOrCfg
|
|
39
|
+
: monthDate;
|
|
40
|
+
if (BanglaCalendar.isBanglaDateString(dateBnYrOrCfg)) {
|
|
41
|
+
const parts = dateBnYrOrCfg.replace(/['"]/g, '').split('-');
|
|
42
|
+
bnYear = (0, convert_1.banglaToDigit)(parts[0]);
|
|
43
|
+
bnMonth = (0, convert_1.banglaToDigit)(parts[1]);
|
|
44
|
+
bnDate = (0, convert_1.banglaToDigit)(parts[2]);
|
|
45
|
+
}
|
|
46
|
+
const { gregYear } = this.#processGregYear(bnYear, bnMonth);
|
|
47
|
+
const { bnMonthTable } = this.#getGregYearBnMonthTable(gregYear, bnYear);
|
|
48
|
+
const monthRange = bnMonthTable[bnMonth - 1];
|
|
49
|
+
if (bnDate > monthRange) {
|
|
50
|
+
bnDate -= monthRange;
|
|
51
|
+
if (bnMonth === 12) {
|
|
52
|
+
bnMonth = 1;
|
|
53
|
+
bnYear += 1;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
bnMonth += 1;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this.year = {
|
|
60
|
+
bn: (0, convert_1.digitToBangla)(bnYear),
|
|
61
|
+
en: bnYear,
|
|
62
|
+
};
|
|
63
|
+
this.month = {
|
|
64
|
+
bn: (0, convert_1.digitToBangla)(bnMonth),
|
|
65
|
+
en: bnMonth,
|
|
66
|
+
};
|
|
67
|
+
this.date = {
|
|
68
|
+
bn: (0, convert_1.digitToBangla)(bnDate),
|
|
69
|
+
en: bnDate,
|
|
70
|
+
};
|
|
71
|
+
const { gy, gm, gd, wd } = (0, helpers_1._extractDateUnits)(this.toDate());
|
|
72
|
+
this.gregorian = { year: gy, month: gm, date: gd };
|
|
73
|
+
this.weekDay = wd;
|
|
74
|
+
this.isoWeekDay = wd === 0 ? 7 : wd;
|
|
75
|
+
}
|
|
76
|
+
get [Symbol.toStringTag]() {
|
|
77
|
+
return this.toJSON();
|
|
78
|
+
}
|
|
79
|
+
isLeapYear() {
|
|
80
|
+
const { gregYear } = this.#processGregYear();
|
|
81
|
+
return this.#getGregYearBnMonthTable(gregYear).isBnLeapYear;
|
|
82
|
+
}
|
|
83
|
+
toDate() {
|
|
84
|
+
const { baseGregYear, gregYear } = this.#processGregYear();
|
|
85
|
+
const { bnMonthTable } = this.#getGregYearBnMonthTable(gregYear);
|
|
86
|
+
const epoch = Date.UTC(baseGregYear, 3, 13);
|
|
87
|
+
let days = this.date.en;
|
|
88
|
+
for (let i = 0; i < this.month.en - 1; i++) {
|
|
89
|
+
days += bnMonthTable[i];
|
|
90
|
+
}
|
|
91
|
+
return new Date(days * constants_1.MS_PER_DAY + epoch);
|
|
92
|
+
}
|
|
93
|
+
getSeasonName(locale) {
|
|
94
|
+
return (0, helpers_1._getBnSeason)(this.month.en - 1, locale);
|
|
95
|
+
}
|
|
96
|
+
getMonthName(locale) {
|
|
97
|
+
const MONTH = constants_1.BN_MONTHS[this.month.en - 1];
|
|
98
|
+
return (locale === 'en' ? MONTH.en : MONTH.bn);
|
|
99
|
+
}
|
|
100
|
+
getDayName(locale) {
|
|
101
|
+
const DAY = constants_1.BN_DAYS[this.weekDay];
|
|
102
|
+
return (locale === 'en' ? DAY.en : DAY.bn);
|
|
103
|
+
}
|
|
104
|
+
startOfMonth() {
|
|
105
|
+
const { year, month, variant } = this;
|
|
106
|
+
return new BanglaCalendar(year.en, month.en, 1, { variant });
|
|
107
|
+
}
|
|
108
|
+
endOfMonth() {
|
|
109
|
+
const { year, month, variant } = this;
|
|
110
|
+
return new BanglaCalendar(year.en, month.en, this.daysInMonth(), { variant });
|
|
111
|
+
}
|
|
112
|
+
startOfYear() {
|
|
113
|
+
const { year, variant } = this;
|
|
114
|
+
return new BanglaCalendar(year.en, 1, 1, { variant });
|
|
115
|
+
}
|
|
116
|
+
endOfYear() {
|
|
117
|
+
const { year, variant } = this;
|
|
118
|
+
return new BanglaCalendar(year.en, 12, 30, { variant });
|
|
119
|
+
}
|
|
120
|
+
daysInMonth(month) {
|
|
121
|
+
const { gregYear } = this.#processGregYear();
|
|
122
|
+
const { bnMonthTable } = this.#getGregYearBnMonthTable(gregYear);
|
|
123
|
+
return bnMonthTable[(month ?? this.month.en) - 1];
|
|
124
|
+
}
|
|
125
|
+
toJSON() {
|
|
126
|
+
const { year, month, date } = this;
|
|
127
|
+
return `${year.bn.padStart(4, '০')}-${month.bn.padStart(2, '০')}-${date.bn.padStart(2, '০')}`;
|
|
128
|
+
}
|
|
129
|
+
toString() {
|
|
130
|
+
return this.#toString('bn');
|
|
131
|
+
}
|
|
132
|
+
toStringEn() {
|
|
133
|
+
return this.#toString('en');
|
|
134
|
+
}
|
|
135
|
+
format(format) {
|
|
136
|
+
const { year, month, date, weekDay } = this;
|
|
137
|
+
const seasonName = this.getSeasonName();
|
|
138
|
+
const M_NAME = constants_1.BN_MONTHS[month.en - 1];
|
|
139
|
+
const D_NAME = constants_1.BN_DAYS[weekDay];
|
|
140
|
+
const paddedYear = year.bn.padStart(4, '০');
|
|
141
|
+
const dateComponents = {
|
|
142
|
+
YYYY: paddedYear,
|
|
143
|
+
YY: paddedYear.slice(-2),
|
|
144
|
+
yyyy: paddedYear,
|
|
145
|
+
yy: paddedYear.slice(-2),
|
|
146
|
+
M: month.bn,
|
|
147
|
+
MM: month.bn.padStart(2, '০'),
|
|
148
|
+
mmm: M_NAME.short,
|
|
149
|
+
mmmm: M_NAME.bn,
|
|
150
|
+
d: D_NAME.short,
|
|
151
|
+
dd: D_NAME.bn.replace('বার', ''),
|
|
152
|
+
ddd: D_NAME.bn,
|
|
153
|
+
D: date.bn,
|
|
154
|
+
DD: date.bn.padStart(2, '০'),
|
|
155
|
+
Do: date.bn,
|
|
156
|
+
S: seasonName,
|
|
157
|
+
SS: seasonName + 'কাল',
|
|
158
|
+
};
|
|
159
|
+
return (0, helpers_1._formatDateCore)(format || 'ddd, DD mmmm (SS), YYYY বঙ্গাব্দ', dateComponents);
|
|
160
|
+
}
|
|
161
|
+
#processGregYear(bnYear, bnMonth) {
|
|
162
|
+
const baseGregYear = bnYear ?? this.year.en + constants_1.BN_YEAR_OFFSET;
|
|
163
|
+
const gregYear = (bnMonth ?? this.month.en) > 10 ? baseGregYear + 1 : baseGregYear;
|
|
164
|
+
return { baseGregYear, gregYear };
|
|
165
|
+
}
|
|
166
|
+
#getGregYearBnMonthTable(gregYear, bnYear) {
|
|
167
|
+
const isBnLeapYear = (0, helpers_1._isBnLeapYear)(bnYear ?? this.year.en, gregYear, this.variant);
|
|
168
|
+
const bnMonthTable = isBnLeapYear ?
|
|
169
|
+
constants_1.BN_MONTH_TABLES?.[this.variant].leap
|
|
170
|
+
: constants_1.BN_MONTH_TABLES?.[this.variant].normal;
|
|
171
|
+
return { bnMonthTable, isBnLeapYear };
|
|
172
|
+
}
|
|
173
|
+
#processVariants(v1, v2, v3, v4) {
|
|
174
|
+
return (this.$hasVariantConfig(v1) ? v1.variant
|
|
175
|
+
: this.$hasVariantConfig(v2) ? v2.variant
|
|
176
|
+
: this.$hasVariantConfig(v3) ? v3.variant
|
|
177
|
+
: this.$hasVariantConfig(v4) ? v4.variant
|
|
178
|
+
: 'revised-2019');
|
|
179
|
+
}
|
|
180
|
+
#processDate(date) {
|
|
181
|
+
const bnYear = (0, helpers_1._getBnYear)(date);
|
|
182
|
+
const { days, monthIdx } = (0, helpers_1._bnDaysMonthIdx)(date, this.variant);
|
|
183
|
+
return {
|
|
184
|
+
year: bnYear,
|
|
185
|
+
month: (monthIdx + 1),
|
|
186
|
+
monthDate: (days + 1),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
#toString(lcl = 'bn') {
|
|
190
|
+
const { year, date } = this;
|
|
191
|
+
return `${this.getDayName(lcl)}, ${date[lcl]} ${this.getMonthName(lcl)}, ${year[lcl]} [${this.getSeasonName(lcl)}]`;
|
|
192
|
+
}
|
|
193
|
+
$hasVariantConfig(value) {
|
|
194
|
+
return ((0, non_primitives_1.isObjectWithKeys)(value, ['variant']) &&
|
|
195
|
+
(0, primitives_1.isNonEmptyString)(value.variant) &&
|
|
196
|
+
(value.variant === 'revised-1966' || value.variant === 'revised-2019'));
|
|
197
|
+
}
|
|
198
|
+
static isBanglaYear(value) {
|
|
199
|
+
return (0, primitives_1.isNonEmptyString)(value) && /^(?:০{0,3}[১-৯][০-৯]{0,3}|০)$/.test(value.trim());
|
|
200
|
+
}
|
|
201
|
+
static isBanglaYearEn(value) {
|
|
202
|
+
return (0, primitives_1.isInteger)(value) && value >= 0 && value <= 9999;
|
|
203
|
+
}
|
|
204
|
+
static isBanglaMonth(value) {
|
|
205
|
+
return (0, primitives_1.isNonEmptyString)(value) && /^(?:০?[১-৯]|১০|১১|১২)$/.test(value.trim());
|
|
206
|
+
}
|
|
207
|
+
static isBanglaMonthEn(value) {
|
|
208
|
+
return (0, primitives_1.isInteger)(value) && value >= 1 && value <= 12;
|
|
209
|
+
}
|
|
210
|
+
static isBanglaDate(value) {
|
|
211
|
+
return (0, primitives_1.isNonEmptyString)(value) && /^(?:০?[১-৯]|[১২][০-৯]|৩০|৩১)$/.test(value.trim());
|
|
212
|
+
}
|
|
213
|
+
static isBanglaDateEn(value) {
|
|
214
|
+
return (0, primitives_1.isInteger)(value) && value >= 1 && value <= 31;
|
|
215
|
+
}
|
|
216
|
+
static isBanglaDateString(value) {
|
|
217
|
+
if ((0, primitives_1.isNonEmptyString)(value) && value.includes('-')) {
|
|
218
|
+
const [year, month, date] = value.replace(/['"]/g, '').split('-');
|
|
219
|
+
return (BanglaCalendar.isBanglaYear(year) &&
|
|
220
|
+
BanglaCalendar.isBanglaMonth(month) &&
|
|
221
|
+
BanglaCalendar.isBanglaDate(date));
|
|
222
|
+
}
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.BanglaCalendar = BanglaCalendar;
|
|
227
|
+
exports.BnCalendar = BanglaCalendar;
|
|
228
|
+
exports.Bongabdo = BanglaCalendar;
|
package/dist/cjs/date/Chronos.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.INTERNALS = exports.chronos = exports.Chronos = void 0;
|
|
4
|
+
exports.INTERNALS = exports.Chronus = exports.chronusts = exports.chronusjs = exports.chronus = exports.chronosts = exports.chronosjs = exports.chronos = exports.Chronos = void 0;
|
|
5
5
|
const non_primitives_1 = require("../guards/non-primitives");
|
|
6
6
|
const primitives_1 = require("../guards/primitives");
|
|
7
7
|
const constants_1 = require("./constants");
|
|
@@ -37,7 +37,7 @@ class Chronos {
|
|
|
37
37
|
timeZoneId;
|
|
38
38
|
$tzTracker;
|
|
39
39
|
constructor(valueOrYear, month, date, hours, minutes, seconds, ms) {
|
|
40
|
-
if (
|
|
40
|
+
if ((0, primitives_1.isNumber)(valueOrYear) && (0, primitives_1.isNumber)(month)) {
|
|
41
41
|
this.#date = new Date(valueOrYear, month - 1, date ?? 1, hours ?? 0, minutes ?? 0, seconds ?? 0, ms ?? 0);
|
|
42
42
|
this.native = this.#date;
|
|
43
43
|
}
|
|
@@ -104,7 +104,9 @@ class Chronos {
|
|
|
104
104
|
return this.#date.getTime();
|
|
105
105
|
}
|
|
106
106
|
#toNewDate(value) {
|
|
107
|
-
const date = value instanceof _a ?
|
|
107
|
+
const date = value instanceof _a ?
|
|
108
|
+
value.toDate()
|
|
109
|
+
: new Date((0, primitives_1.isString)(value) ? value.replace(/['"]/g, '') : (value ?? Date.now()));
|
|
108
110
|
if (isNaN(date.getTime())) {
|
|
109
111
|
throw new Error('Provided date is invalid!');
|
|
110
112
|
}
|
|
@@ -138,7 +140,7 @@ class Chronos {
|
|
|
138
140
|
};
|
|
139
141
|
const y = _getUnitValue('FullYear'), mo = _getUnitValue('Month'), d = _getUnitValue('Day'), dt = _getUnitValue('Date'), h = _getUnitValue('Hours'), m = _getUnitValue('Minutes'), s = _getUnitValue('Seconds'), ms = _getUnitValue('Milliseconds');
|
|
140
142
|
const offset = useUTC ? 'Z' : this.getTimeZoneOffset();
|
|
141
|
-
return (0, helpers_1.
|
|
143
|
+
return (0, helpers_1._formatDate)(format, y, mo, d, dt, h, m, s, ms, offset);
|
|
142
144
|
}
|
|
143
145
|
#removeUTCFromISO(local = true) {
|
|
144
146
|
const search = /\.\d+(Z|[+-]\d{2}:\d{2})?$/;
|
|
@@ -216,16 +218,16 @@ class Chronos {
|
|
|
216
218
|
return this.toDate().toISOString();
|
|
217
219
|
}
|
|
218
220
|
toLocaleString(locales, options) {
|
|
219
|
-
return this.
|
|
221
|
+
return this.#date.toLocaleString(locales, options);
|
|
220
222
|
}
|
|
221
223
|
getTimeStamp() {
|
|
222
224
|
return this.toDate().getTime();
|
|
223
225
|
}
|
|
224
226
|
format(format, useUTC = false) {
|
|
225
|
-
return this.#format(format
|
|
227
|
+
return this.#format(format || 'dd, mmm DD, YYYY HH:mm:ss', useUTC);
|
|
226
228
|
}
|
|
227
229
|
formatStrict(format, useUTC = false) {
|
|
228
|
-
return this.#format(format
|
|
230
|
+
return this.#format(format || 'dd, mmm DD, YYYY HH:mm:ss', useUTC);
|
|
229
231
|
}
|
|
230
232
|
formatUTC(format = 'dd, mmm DD, YYYY HH:mm:ss:mss') {
|
|
231
233
|
return this.#format(format, true);
|
|
@@ -617,8 +619,8 @@ class Chronos {
|
|
|
617
619
|
const dates = [];
|
|
618
620
|
const startTime = startDate.#timestamp;
|
|
619
621
|
const endTime = endDate.#timestamp;
|
|
620
|
-
const step = (startTime <= endTime ? 1 : -1) *
|
|
621
|
-
const totalDays = Math.floor(Math.abs(endTime - startTime) /
|
|
622
|
+
const step = (startTime <= endTime ? 1 : -1) * constants_1.MS_PER_DAY;
|
|
623
|
+
const totalDays = Math.floor(Math.abs(endTime - startTime) / constants_1.MS_PER_DAY);
|
|
622
624
|
for (let i = 0; i <= totalDays; i++) {
|
|
623
625
|
const ts = startTime + i * step;
|
|
624
626
|
const wDay = new Date(ts).getDay();
|
|
@@ -724,11 +726,8 @@ class Chronos {
|
|
|
724
726
|
return new _a(utc).#withOrigin('utc', 'UTC+00:00', 'Greenwich Mean Time', 'UTC');
|
|
725
727
|
}
|
|
726
728
|
static formatTimePart(time, format) {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
}
|
|
730
|
-
const timeWithDate = `${new _a().#format('YYYY-MM-DD')}T${normalizeOffset(time)}`;
|
|
731
|
-
return new _a(timeWithDate).formatStrict(format ?? 'hh:mm:ss a');
|
|
729
|
+
const timeWithDate = `${new _a().#format('YYYY-MM-DD')}T${(0, helpers_1._normalizeOffset)(time)}`;
|
|
730
|
+
return new _a(timeWithDate).#format(format || 'hh:mm:ss a');
|
|
732
731
|
}
|
|
733
732
|
static getDatesForDay(day, options) {
|
|
734
733
|
let startDate = new _a(), endDate = startDate.addWeeks(4);
|
|
@@ -750,7 +749,7 @@ class Chronos {
|
|
|
750
749
|
endDate = endDate.startOf('day');
|
|
751
750
|
}
|
|
752
751
|
const result = [];
|
|
753
|
-
const step = (startDate.isBefore(endDate, 'day') ? 1 : -1) *
|
|
752
|
+
const step = (startDate.isBefore(endDate, 'day') ? 1 : -1) * constants_1.MS_PER_DAY;
|
|
754
753
|
const totalDays = Math.abs(endDate.diff(startDate, 'day'));
|
|
755
754
|
const currentTime = startDate.#timestamp;
|
|
756
755
|
let firstOffset = 0;
|
|
@@ -786,7 +785,7 @@ class Chronos {
|
|
|
786
785
|
}
|
|
787
786
|
static isLeapYear(date) {
|
|
788
787
|
let year;
|
|
789
|
-
if (
|
|
788
|
+
if ((0, primitives_1.isNumber)(date)) {
|
|
790
789
|
if (date > 0 && date <= 9999) {
|
|
791
790
|
year = date;
|
|
792
791
|
}
|
|
@@ -822,8 +821,14 @@ class Chronos {
|
|
|
822
821
|
}
|
|
823
822
|
}
|
|
824
823
|
exports.Chronos = Chronos;
|
|
824
|
+
exports.Chronus = Chronos;
|
|
825
825
|
_a = Chronos;
|
|
826
826
|
var chronos_fn_1 = require("./chronos-fn");
|
|
827
827
|
Object.defineProperty(exports, "chronos", { enumerable: true, get: function () { return chronos_fn_1.chronos; } });
|
|
828
|
+
Object.defineProperty(exports, "chronosjs", { enumerable: true, get: function () { return chronos_fn_1.chronosjs; } });
|
|
829
|
+
Object.defineProperty(exports, "chronosts", { enumerable: true, get: function () { return chronos_fn_1.chronosts; } });
|
|
830
|
+
Object.defineProperty(exports, "chronus", { enumerable: true, get: function () { return chronos_fn_1.chronus; } });
|
|
831
|
+
Object.defineProperty(exports, "chronusjs", { enumerable: true, get: function () { return chronos_fn_1.chronusjs; } });
|
|
832
|
+
Object.defineProperty(exports, "chronusts", { enumerable: true, get: function () { return chronos_fn_1.chronusts; } });
|
|
828
833
|
var constants_2 = require("./constants");
|
|
829
834
|
Object.defineProperty(exports, "INTERNALS", { enumerable: true, get: function () { return constants_2.INTERNALS; } });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.chronos = void 0;
|
|
3
|
+
exports.chronusts = exports.chronusjs = exports.chronus = exports.chronosts = exports.chronosjs = exports.chronos = void 0;
|
|
4
4
|
const Chronos_1 = require("./Chronos");
|
|
5
|
-
const chronos = (valueOrYear, month, date, hours, minutes, seconds, ms) => {
|
|
5
|
+
const $chronos = (valueOrYear, month, date, hours, minutes, seconds, ms) => {
|
|
6
6
|
if (typeof valueOrYear === 'number' && typeof month === 'number') {
|
|
7
7
|
return new Chronos_1.Chronos(valueOrYear, month, date ?? 1, hours ?? 0, minutes ?? 0, seconds ?? 0, ms ?? 0);
|
|
8
8
|
}
|
|
@@ -10,27 +10,29 @@ const chronos = (valueOrYear, month, date, hours, minutes, seconds, ms) => {
|
|
|
10
10
|
return new Chronos_1.Chronos(valueOrYear);
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
function _isChronosStaticKey(prop) {
|
|
14
|
+
return (prop in Chronos_1.Chronos &&
|
|
15
|
+
prop !== 'prototype' &&
|
|
16
|
+
prop !== 'name' &&
|
|
17
|
+
prop !== 'length' &&
|
|
18
|
+
typeof Chronos_1.Chronos[prop] === 'function');
|
|
19
|
+
}
|
|
20
|
+
exports.chronos = new Proxy($chronos, {
|
|
14
21
|
get(target, prop, receiver) {
|
|
15
22
|
if (prop in target) {
|
|
16
23
|
return Reflect.get(target, prop, receiver);
|
|
17
24
|
}
|
|
18
|
-
if (prop
|
|
19
|
-
prop !== 'prototype' &&
|
|
20
|
-
prop !== 'name' &&
|
|
21
|
-
prop !== 'length' &&
|
|
22
|
-
typeof Chronos_1.Chronos[prop] === 'function') {
|
|
25
|
+
if (_isChronosStaticKey(prop)) {
|
|
23
26
|
return Chronos_1.Chronos[prop];
|
|
24
27
|
}
|
|
25
28
|
return Reflect.get(target, prop, receiver);
|
|
26
29
|
},
|
|
27
30
|
has(target, prop) {
|
|
28
|
-
return
|
|
29
|
-
(prop in Chronos_1.Chronos &&
|
|
30
|
-
prop !== 'prototype' &&
|
|
31
|
-
prop !== 'name' &&
|
|
32
|
-
prop !== 'length' &&
|
|
33
|
-
typeof Chronos_1.Chronos[prop] === 'function'));
|
|
31
|
+
return prop in target || _isChronosStaticKey(prop);
|
|
34
32
|
},
|
|
35
33
|
});
|
|
36
|
-
exports.
|
|
34
|
+
exports.chronosjs = exports.chronos;
|
|
35
|
+
exports.chronosts = exports.chronos;
|
|
36
|
+
exports.chronus = exports.chronos;
|
|
37
|
+
exports.chronusjs = exports.chronos;
|
|
38
|
+
exports.chronusts = exports.chronos;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MS_MAP = exports.TIME_UNIT_VARIANTS = exports.ZODIAC_PRESETS = exports.VEDIC_ZODIAC_SIGNS = exports.WESTERN_ZODIAC_SIGNS = exports.DATE_PART_RANGES = exports.SORTED_TIME_FORMATS = exports.
|
|
3
|
+
exports.BN_MONTHS = exports.BN_DAYS = exports.BN_SEASONS = exports.BN_MONTH_TABLES = exports.BN_YEAR_OFFSET = exports.LOCALE_NUMBERING_SYSTEMS = exports.LOCALE_CALENDARS = exports.MS_MAP = exports.TIME_UNIT_VARIANTS = exports.ZODIAC_PRESETS = exports.VEDIC_ZODIAC_SIGNS = exports.WESTERN_ZODIAC_SIGNS = exports.DATE_PART_RANGES = exports.SORTED_TIME_FORMATS = exports.EXTRA_FORMATS = exports.TIME_FORMATS = exports.MILLISECOND_FORMATS = exports.SECOND_FORMATS = exports.MINUTE_FORMATS = exports.HOUR_FORMATS = exports.DAY_FORMATS = exports.DATE_FORMATS = exports.MONTH_FORMATS = exports.YEAR_FORMATS = exports.MONTHS = exports.DAYS = exports.MS_PER_DAY = exports.INTERNALS = void 0;
|
|
4
4
|
exports.INTERNALS = Symbol('Internals');
|
|
5
|
+
exports.MS_PER_DAY = 86400000;
|
|
5
6
|
exports.DAYS = /* @__PURE__ */ Object.freeze([
|
|
6
7
|
'Sunday',
|
|
7
8
|
'Monday',
|
|
@@ -37,9 +38,9 @@ exports.DAY_FORMATS = /* @__PURE__ */ Object.freeze(['d', 'dd', 'ddd']);
|
|
|
37
38
|
exports.HOUR_FORMATS = /* @__PURE__ */ Object.freeze(['H', 'HH', 'hh', 'h']);
|
|
38
39
|
exports.MINUTE_FORMATS = /* @__PURE__ */ Object.freeze(['mm', 'm']);
|
|
39
40
|
exports.SECOND_FORMATS = /* @__PURE__ */ Object.freeze(['ss', 's']);
|
|
40
|
-
exports.ZONE_FORMATS = /* @__PURE__ */ Object.freeze(['ZZ']);
|
|
41
41
|
exports.MILLISECOND_FORMATS = /* @__PURE__ */ Object.freeze(['ms', 'mss']);
|
|
42
42
|
exports.TIME_FORMATS = /* @__PURE__ */ Object.freeze(['a', 'A']);
|
|
43
|
+
exports.EXTRA_FORMATS = /* @__PURE__ */ Object.freeze(['Z', 'ZZ', 'S', 'SS']);
|
|
43
44
|
exports.SORTED_TIME_FORMATS = /* @__PURE__ */ Object.freeze([
|
|
44
45
|
...exports.YEAR_FORMATS,
|
|
45
46
|
...exports.MONTH_FORMATS,
|
|
@@ -50,7 +51,7 @@ exports.SORTED_TIME_FORMATS = /* @__PURE__ */ Object.freeze([
|
|
|
50
51
|
...exports.SECOND_FORMATS,
|
|
51
52
|
...exports.MILLISECOND_FORMATS,
|
|
52
53
|
...exports.TIME_FORMATS,
|
|
53
|
-
...exports.
|
|
54
|
+
...exports.EXTRA_FORMATS,
|
|
54
55
|
].sort((a, b) => b.length - a.length));
|
|
55
56
|
exports.DATE_PART_RANGES = /* @__PURE__ */ Object.freeze({
|
|
56
57
|
night: ['21', '23'],
|
|
@@ -151,3 +152,144 @@ exports.MS_MAP = /* @__PURE__ */ Object.freeze((() => {
|
|
|
151
152
|
milliseconds: 1,
|
|
152
153
|
};
|
|
153
154
|
})());
|
|
155
|
+
exports.LOCALE_CALENDARS = /* @__PURE__ */ Object.freeze([
|
|
156
|
+
'buddhist',
|
|
157
|
+
'chinese',
|
|
158
|
+
'coptic',
|
|
159
|
+
'dangi',
|
|
160
|
+
'ethioaa',
|
|
161
|
+
'ethiopic',
|
|
162
|
+
'gregory',
|
|
163
|
+
'hebrew',
|
|
164
|
+
'indian',
|
|
165
|
+
'islamic',
|
|
166
|
+
'islamic-civil',
|
|
167
|
+
'islamic-rgsa',
|
|
168
|
+
'islamic-tbla',
|
|
169
|
+
'islamic-umalqura',
|
|
170
|
+
'iso8601',
|
|
171
|
+
'japanese',
|
|
172
|
+
'persian',
|
|
173
|
+
'roc',
|
|
174
|
+
]);
|
|
175
|
+
exports.LOCALE_NUMBERING_SYSTEMS = /* @__PURE__ */ Object.freeze([
|
|
176
|
+
'adlm',
|
|
177
|
+
'ahom',
|
|
178
|
+
'arab',
|
|
179
|
+
'arabext',
|
|
180
|
+
'bali',
|
|
181
|
+
'beng',
|
|
182
|
+
'bhks',
|
|
183
|
+
'brah',
|
|
184
|
+
'cakm',
|
|
185
|
+
'cham',
|
|
186
|
+
'deva',
|
|
187
|
+
'diak',
|
|
188
|
+
'fullwide',
|
|
189
|
+
'gara',
|
|
190
|
+
'gong',
|
|
191
|
+
'gonm',
|
|
192
|
+
'gujr',
|
|
193
|
+
'gukh',
|
|
194
|
+
'guru',
|
|
195
|
+
'hanidec',
|
|
196
|
+
'hmng',
|
|
197
|
+
'hmnp',
|
|
198
|
+
'java',
|
|
199
|
+
'kali',
|
|
200
|
+
'kawi',
|
|
201
|
+
'khmr',
|
|
202
|
+
'knda',
|
|
203
|
+
'krai',
|
|
204
|
+
'lana',
|
|
205
|
+
'lanatham',
|
|
206
|
+
'laoo',
|
|
207
|
+
'latn',
|
|
208
|
+
'lepc',
|
|
209
|
+
'limb',
|
|
210
|
+
'mathbold',
|
|
211
|
+
'mathdbl',
|
|
212
|
+
'mathmono',
|
|
213
|
+
'mathsanb',
|
|
214
|
+
'mathsans',
|
|
215
|
+
'mlym',
|
|
216
|
+
'modi',
|
|
217
|
+
'mong',
|
|
218
|
+
'mroo',
|
|
219
|
+
'mtei',
|
|
220
|
+
'mymr',
|
|
221
|
+
'mymrepka',
|
|
222
|
+
'mymrpao',
|
|
223
|
+
'mymrshan',
|
|
224
|
+
'mymrtlng',
|
|
225
|
+
'nagm',
|
|
226
|
+
'newa',
|
|
227
|
+
'nkoo',
|
|
228
|
+
'olck',
|
|
229
|
+
'onao',
|
|
230
|
+
'orya',
|
|
231
|
+
'osma',
|
|
232
|
+
'outlined',
|
|
233
|
+
'rohg',
|
|
234
|
+
'saur',
|
|
235
|
+
'segment',
|
|
236
|
+
'shrd',
|
|
237
|
+
'sind',
|
|
238
|
+
'sinh',
|
|
239
|
+
'sora',
|
|
240
|
+
'sund',
|
|
241
|
+
'sunu',
|
|
242
|
+
'takr',
|
|
243
|
+
'talu',
|
|
244
|
+
'tamldec',
|
|
245
|
+
'telu',
|
|
246
|
+
'thai',
|
|
247
|
+
'tibt',
|
|
248
|
+
'tirh',
|
|
249
|
+
'tnsa',
|
|
250
|
+
'vaii',
|
|
251
|
+
'wara',
|
|
252
|
+
'wcho',
|
|
253
|
+
]);
|
|
254
|
+
exports.BN_YEAR_OFFSET = 593;
|
|
255
|
+
exports.BN_MONTH_TABLES = /* @__PURE__ */ Object.freeze({
|
|
256
|
+
'revised-2019': {
|
|
257
|
+
normal: [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 29, 30],
|
|
258
|
+
leap: [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30],
|
|
259
|
+
},
|
|
260
|
+
'revised-1966': {
|
|
261
|
+
normal: [31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30, 30],
|
|
262
|
+
leap: [31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 31, 30],
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
exports.BN_SEASONS = /* @__PURE__ */ Object.freeze([
|
|
266
|
+
{ bn: 'গ্রীষ্ম', en: 'Grisma (Summer)' },
|
|
267
|
+
{ bn: 'বর্ষা', en: 'Barsa (Monsoon)' },
|
|
268
|
+
{ bn: 'শরৎ', en: 'Sarat (Autumn)' },
|
|
269
|
+
{ bn: 'হেমন্ত', en: 'Hemanta (Late-Autumn)' },
|
|
270
|
+
{ bn: 'শীত', en: 'Shhit (Winter)' },
|
|
271
|
+
{ bn: 'বসন্ত', en: 'Basanta (Spring)' },
|
|
272
|
+
]);
|
|
273
|
+
exports.BN_DAYS = /* @__PURE__ */ Object.freeze([
|
|
274
|
+
{ bn: 'রবিবার', en: 'Robibar (Sunday)', short: 'র' },
|
|
275
|
+
{ bn: 'সোমবার', en: 'Shombar (Monday)', short: 'সো' },
|
|
276
|
+
{ bn: 'মঙ্গলবার', en: 'Mongolbar (Tuesday)', short: 'ম' },
|
|
277
|
+
{ bn: 'বুধবার', en: 'Budhbar (Wednesday)', short: 'বু' },
|
|
278
|
+
{ bn: 'বৃহস্পতিবার', en: 'Brihoshpotibar (Thursday)', short: 'বৃ' },
|
|
279
|
+
{ bn: 'শুক্রবার', en: 'Shukrobar (Friday)', short: 'শু' },
|
|
280
|
+
{ bn: 'শনিবার', en: 'Shonibar (Saturday)', short: 'শ' },
|
|
281
|
+
]);
|
|
282
|
+
exports.BN_MONTHS = /* @__PURE__ */ Object.freeze([
|
|
283
|
+
{ bn: 'বৈশাখ', en: 'Boishakh', short: 'বৈ' },
|
|
284
|
+
{ bn: 'জ্যৈষ্ঠ', en: 'Joishtho', short: 'জ্য' },
|
|
285
|
+
{ bn: 'আষাঢ়', en: 'Asharh', short: 'আ' },
|
|
286
|
+
{ bn: 'শ্রাবণ', en: 'Srabon', short: 'শ্রা' },
|
|
287
|
+
{ bn: 'ভাদ্র', en: 'Bhadro', short: 'ভা' },
|
|
288
|
+
{ bn: 'আশ্বিন', en: 'Ashwin', short: 'আ' },
|
|
289
|
+
{ bn: 'কার্তিক', en: 'Kartik', short: 'কা' },
|
|
290
|
+
{ bn: 'অগ্রহায়ণ', en: 'Ogrohayon', short: 'অ' },
|
|
291
|
+
{ bn: 'পৌষ', en: 'Poush', short: 'পৌ' },
|
|
292
|
+
{ bn: 'মাঘ', en: 'Magh', short: 'মা' },
|
|
293
|
+
{ bn: 'ফাল্গুন', en: 'Falgun', short: 'ফা' },
|
|
294
|
+
{ bn: 'চৈত্র', en: 'Choitro', short: 'চৈ' },
|
|
295
|
+
]);
|