chronos-date 1.0.2 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/basic-DqKyujoj.mjs +382 -0
- package/dist/basic-DsQqC5nZ.cjs +466 -0
- package/dist/constants.cjs +43 -1
- package/dist/constants.d.cts +17 -1
- package/dist/constants.d.mts +17 -1
- package/dist/constants.mjs +21 -1
- package/dist/convert-DbgntRVW.cjs +49 -0
- package/dist/convert-mMaI4YP0.mjs +38 -0
- package/dist/greet-D07t2_e6.mjs +51 -0
- package/dist/greet-hjVsd2dt.cjs +56 -0
- package/dist/guards.cjs +140 -1
- package/dist/guards.d.cts +18 -2
- package/dist/guards.d.mts +18 -2
- package/dist/guards.mjs +131 -1
- package/dist/helpers-CQzi908i.cjs +278 -0
- package/dist/helpers-DEf4sevD.mjs +201 -0
- package/dist/index.cjs +1477 -1
- package/dist/index.d.cts +18 -2
- package/dist/index.d.mts +18 -2
- package/dist/index.mjs +1474 -1
- package/dist/non-primitives-D9zxCwX8.cjs +68 -0
- package/dist/non-primitives-DBtomDty.mjs +38 -0
- package/dist/plugins/banglaPlugin.cjs +137 -1
- package/dist/plugins/banglaPlugin.d.cts +19 -3
- package/dist/plugins/banglaPlugin.d.mts +19 -3
- package/dist/plugins/banglaPlugin.mjs +136 -1
- package/dist/plugins/businessPlugin.cjs +134 -1
- package/dist/plugins/businessPlugin.d.cts +17 -1
- package/dist/plugins/businessPlugin.d.mts +17 -1
- package/dist/plugins/businessPlugin.mjs +133 -1
- package/dist/plugins/dateRangePlugin.cjs +62 -1
- package/dist/plugins/dateRangePlugin.d.cts +19 -3
- package/dist/plugins/dateRangePlugin.d.mts +19 -3
- package/dist/plugins/dateRangePlugin.mjs +61 -1
- package/dist/plugins/dayPartPlugin.cjs +42 -1
- package/dist/plugins/dayPartPlugin.d.cts +17 -1
- package/dist/plugins/dayPartPlugin.d.mts +17 -1
- package/dist/plugins/dayPartPlugin.mjs +41 -1
- package/dist/plugins/durationPlugin.cjs +107 -1
- package/dist/plugins/durationPlugin.d.cts +17 -1
- package/dist/plugins/durationPlugin.d.mts +17 -1
- package/dist/plugins/durationPlugin.mjs +106 -1
- package/dist/plugins/fromNowPlugin.cjs +96 -1
- package/dist/plugins/fromNowPlugin.d.cts +17 -1
- package/dist/plugins/fromNowPlugin.d.mts +17 -1
- package/dist/plugins/fromNowPlugin.mjs +95 -1
- package/dist/plugins/greetingPlugin.cjs +35 -1
- package/dist/plugins/greetingPlugin.d.cts +17 -1
- package/dist/plugins/greetingPlugin.d.mts +17 -1
- package/dist/plugins/greetingPlugin.mjs +34 -1
- package/dist/plugins/palindromePlugin.cjs +38 -1
- package/dist/plugins/palindromePlugin.d.cts +17 -1
- package/dist/plugins/palindromePlugin.d.mts +17 -1
- package/dist/plugins/palindromePlugin.mjs +37 -1
- package/dist/plugins/relativeTimePlugin.cjs +90 -1
- package/dist/plugins/relativeTimePlugin.d.cts +17 -1
- package/dist/plugins/relativeTimePlugin.d.mts +17 -1
- package/dist/plugins/relativeTimePlugin.mjs +89 -1
- package/dist/plugins/roundPlugin.cjs +85 -1
- package/dist/plugins/roundPlugin.d.cts +17 -1
- package/dist/plugins/roundPlugin.d.mts +17 -1
- package/dist/plugins/roundPlugin.mjs +84 -1
- package/dist/plugins/seasonPlugin.cjs +47 -1
- package/dist/plugins/seasonPlugin.d.cts +17 -1
- package/dist/plugins/seasonPlugin.d.mts +17 -1
- package/dist/plugins/seasonPlugin.mjs +46 -1
- package/dist/plugins/timeZonePlugin.cjs +155 -1
- package/dist/plugins/timeZonePlugin.d.cts +17 -1
- package/dist/plugins/timeZonePlugin.d.mts +17 -1
- package/dist/plugins/timeZonePlugin.mjs +154 -1
- package/dist/plugins/zodiacPlugin.cjs +67 -1
- package/dist/plugins/zodiacPlugin.d.cts +17 -1
- package/dist/plugins/zodiacPlugin.d.mts +17 -1
- package/dist/plugins/zodiacPlugin.mjs +66 -1
- package/dist/primitives-CtuSNmV7.cjs +65 -0
- package/dist/primitives-dXzXlzJw.mjs +35 -0
- package/dist/seasons-B7kK88zq.cjs +434 -0
- package/dist/{seasons-CioTH5Dm.d.mts → seasons-B_kjFWIX.d.mts} +16 -0
- package/dist/{seasons-CsVeJ27s.d.cts → seasons-CpUn45n6.d.cts} +16 -0
- package/dist/seasons-Cq3ah3pV.mjs +368 -0
- package/dist/timezone-BNnHFgki.cjs +5625 -0
- package/dist/timezone-Db2CeL32.mjs +5589 -0
- package/dist/{types-B2fgrJ86.d.mts → types-Cb4gxrgJ.d.mts} +29 -15
- package/dist/{types-DPTQ_yLx.d.cts → types-CdmsXbU_.d.cts} +29 -15
- package/dist/types.cjs +16 -0
- package/dist/types.d.cts +18 -2
- package/dist/types.d.mts +18 -2
- package/dist/types.mjs +17 -1
- package/dist/utilities-BGX8dviZ.mjs +257 -0
- package/dist/utilities-BKtVo78T.mjs +59 -0
- package/dist/utilities-CpF3uys3.cjs +88 -0
- package/dist/utilities-D47SN9EZ.cjs +334 -0
- package/dist/utils.cjs +92 -1
- package/dist/utils.d.cts +20 -4
- package/dist/utils.d.mts +20 -4
- package/dist/utils.mjs +60 -1
- package/package.json +10 -4
- package/dist/basic-CKxaRSHQ.cjs +0 -1
- package/dist/basic-e46DaNAi.mjs +0 -1
- package/dist/convert-Bmp63ats.mjs +0 -1
- package/dist/convert-DrLrcgqz.cjs +0 -1
- package/dist/greet-BBsrvmkn.mjs +0 -1
- package/dist/greet-C-6mruI9.cjs +0 -1
- package/dist/helpers-DGzYnP81.cjs +0 -1
- package/dist/helpers-N1X_Rj_V.mjs +0 -1
- package/dist/non-primitives-B2EE6D6s.mjs +0 -1
- package/dist/non-primitives-Bu3a4WL4.cjs +0 -1
- package/dist/primitives-Cxss_JVF.mjs +0 -1
- package/dist/primitives-Db2FUp4e.cjs +0 -1
- package/dist/seasons-ChAIVphi.mjs +0 -1
- package/dist/seasons-oABOhHcX.cjs +0 -1
- package/dist/timezone-B10UItNO.mjs +0 -1
- package/dist/timezone-CWxbK_7I.cjs +0 -1
- package/dist/utilities-B8dOAQVD.cjs +0 -1
- package/dist/utilities-BJE06bms.mjs +0 -1
- package/dist/utilities-D2-p26DX.cjs +0 -1
- package/dist/utilities-DV_ohS37.mjs +0 -1
|
@@ -1 +1,133 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { s as INTERNALS } from "../basic-DqKyujoj.mjs";
|
|
18
|
+
import { a as isUndefined } from "../primitives-dXzXlzJw.mjs";
|
|
19
|
+
import { a as isValidArray } from "../non-primitives-DBtomDty.mjs";
|
|
20
|
+
|
|
21
|
+
//#region src/plugins/businessPlugin.ts
|
|
22
|
+
/** * Plugin to inject `business` related methods */
|
|
23
|
+
const businessPlugin = ($Chronos) => {
|
|
24
|
+
const { internalDate: $Date, withOrigin, cast, offset } = $Chronos[INTERNALS];
|
|
25
|
+
/** Build weekend mask (array of booleans) based on `week definition` or weekend `length` */
|
|
26
|
+
const _buildWeekendMask = (weekDef, length) => {
|
|
27
|
+
const weekendDays = isValidArray(weekDef) ? [...weekDef].sort() : Array.from({ length }, (_, i) => (weekDef + 7 - 1 - i) % 7).sort();
|
|
28
|
+
const mask = new Array(7).fill(true);
|
|
29
|
+
for (const d of weekendDays) mask[d] = false;
|
|
30
|
+
return mask;
|
|
31
|
+
};
|
|
32
|
+
/** Count workdays (`wd=true`) or weekends(`wd=false`) given a `start weekday`, `total days`, `weekend mask` and optional `step` */
|
|
33
|
+
const _countDays = (sWeek, days, mask, step = 1, wd = true) => {
|
|
34
|
+
let total = Math.floor(days / 7) * mask.filter((m) => wd ? Boolean(m) : !m).length;
|
|
35
|
+
let dayIndex = (sWeek % 7 + 7) % 7;
|
|
36
|
+
for (let i = 0; i < days % 7; i++) {
|
|
37
|
+
if (wd ? Boolean(mask[dayIndex]) : !mask[dayIndex]) total++;
|
|
38
|
+
dayIndex = (dayIndex + step + 7) % 7;
|
|
39
|
+
}
|
|
40
|
+
return total;
|
|
41
|
+
};
|
|
42
|
+
$Chronos.prototype.isWeekend = function(wDef = 0, wLen = 2) {
|
|
43
|
+
const day = $Date(this).getDay();
|
|
44
|
+
if (isValidArray(wDef)) return wDef.includes(day);
|
|
45
|
+
const lastDayOfWeek = (wDef + 6) % 7;
|
|
46
|
+
return Array.from({ length: wLen }, (_, i) => (lastDayOfWeek - i + 7) % 7).includes(day);
|
|
47
|
+
};
|
|
48
|
+
$Chronos.prototype.isWorkday = function(wDef = 0, wLen = 2) {
|
|
49
|
+
return !this.isWeekend(wDef, wLen);
|
|
50
|
+
};
|
|
51
|
+
$Chronos.prototype.nextWorkday = function(wDef = 0, wLen = 2) {
|
|
52
|
+
let nxtWrk = this.addDays(1);
|
|
53
|
+
while (nxtWrk.isWeekend(wDef, wLen)) nxtWrk = nxtWrk.addDays(1);
|
|
54
|
+
return withOrigin(nxtWrk.startOf("day"), "nextWorkday", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
55
|
+
};
|
|
56
|
+
$Chronos.prototype.previousWorkday = function(wDef = 0, wLen = 2) {
|
|
57
|
+
let prevWrk = this.addDays(-1);
|
|
58
|
+
while (prevWrk.isWeekend(wDef, wLen)) prevWrk = prevWrk.addDays(-1);
|
|
59
|
+
return withOrigin(prevWrk.startOf("day"), "previousWorkday", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
60
|
+
};
|
|
61
|
+
$Chronos.prototype.nextWeekend = function(wDef = 0, wLen = 2) {
|
|
62
|
+
let nxtWknd = this.addDays(1);
|
|
63
|
+
while (!nxtWknd.isWeekend(wDef, wLen)) nxtWknd = nxtWknd.addDays(1);
|
|
64
|
+
return withOrigin(nxtWknd.startOf("day"), "nextWeekend", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
65
|
+
};
|
|
66
|
+
$Chronos.prototype.previousWeekend = function(wDef = 0, wLen = 2) {
|
|
67
|
+
let prevWknd = this.addDays(-1);
|
|
68
|
+
while (!prevWknd.isWeekend(wDef, wLen)) prevWknd = prevWknd.addDays(-1);
|
|
69
|
+
return withOrigin(prevWknd.startOf("day"), "previousWeekend", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
70
|
+
};
|
|
71
|
+
$Chronos.prototype.workdaysBetween = function(to, wDef = 0, wLen = 2) {
|
|
72
|
+
const end = cast(to).startOf("day");
|
|
73
|
+
const start = this.startOf("day");
|
|
74
|
+
if (start.isSame(end, "day")) return 0;
|
|
75
|
+
const step = start.isBefore(end, "day") ? 1 : -1;
|
|
76
|
+
const totalDays = Math.abs(end.diff(start, "day"));
|
|
77
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
78
|
+
return _countDays((start.isoWeekDay + step) % 7, totalDays, weekendMask, step);
|
|
79
|
+
};
|
|
80
|
+
$Chronos.prototype.weekendsBetween = function(to, wDef = 0, wLen = 2) {
|
|
81
|
+
const end = cast(to).startOf("day");
|
|
82
|
+
const start = this.startOf("day");
|
|
83
|
+
if (start.isSame(end, "day")) return 0;
|
|
84
|
+
const step = start.isBefore(end, "day") ? 1 : -1;
|
|
85
|
+
const totalDays = Math.abs(end.diff(start, "day"));
|
|
86
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
87
|
+
return _countDays((start.isoWeekDay + step) % 7, totalDays, weekendMask, step, false);
|
|
88
|
+
};
|
|
89
|
+
$Chronos.prototype.workdaysInMonth = function(wDef = 0, wLen = 2) {
|
|
90
|
+
const daysInMonth = this.daysInMonth();
|
|
91
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
92
|
+
return _countDays(this.startOf("month").isoWeekDay % 7, daysInMonth, weekendMask);
|
|
93
|
+
};
|
|
94
|
+
$Chronos.prototype.weekendsInMonth = function(wDef = 0, wLen = 2) {
|
|
95
|
+
const daysInMonth = this.daysInMonth();
|
|
96
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
97
|
+
return _countDays(this.startOf("month").isoWeekDay % 7, daysInMonth, weekendMask, 1, false);
|
|
98
|
+
};
|
|
99
|
+
$Chronos.prototype.workdaysInYear = function(wDef = 0, wLen = 2) {
|
|
100
|
+
const daysInYear = this.isLeapYear() ? 366 : 365;
|
|
101
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
102
|
+
return _countDays(this.startOf("year").isoWeekDay % 7, daysInYear, weekendMask);
|
|
103
|
+
};
|
|
104
|
+
$Chronos.prototype.weekendsInYear = function(wDef = 0, wLen = 2) {
|
|
105
|
+
const daysInYear = this.isLeapYear() ? 366 : 365;
|
|
106
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
107
|
+
return _countDays(this.startOf("year").isoWeekDay % 7, daysInYear, weekendMask, 1, false);
|
|
108
|
+
};
|
|
109
|
+
$Chronos.prototype.isBusinessHour = function(options) {
|
|
110
|
+
const _isBusinessHour = () => {
|
|
111
|
+
const { businessStartHour = 9, businessEndHour = 17 } = options ?? {};
|
|
112
|
+
if (businessStartHour === businessEndHour) return false;
|
|
113
|
+
const hour = $Date(this).getHours();
|
|
114
|
+
if (businessStartHour < businessEndHour) return hour >= businessStartHour && hour < businessEndHour;
|
|
115
|
+
else return hour >= businessStartHour || hour < businessEndHour;
|
|
116
|
+
};
|
|
117
|
+
if (options && "weekendDays" in options && !isUndefined(options?.weekendDays)) return this.isWorkday(options.weekendDays) && _isBusinessHour();
|
|
118
|
+
const { weekStartsOn = 0, weekendLength = 2 } = options ?? {};
|
|
119
|
+
return this.isWorkday(weekStartsOn, weekendLength) && _isBusinessHour();
|
|
120
|
+
};
|
|
121
|
+
$Chronos.prototype.toFiscalQuarter = function(startMonth = 7) {
|
|
122
|
+
const adjusted = (this.isoMonth - startMonth + 12) % 12;
|
|
123
|
+
return Math.floor(adjusted / 3) + 1;
|
|
124
|
+
};
|
|
125
|
+
$Chronos.prototype.toAcademicYear = function() {
|
|
126
|
+
const year = this.year;
|
|
127
|
+
if (this.month >= 6) return `${year}-${year + 1}`;
|
|
128
|
+
else return `${year - 1}-${year}`;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
//#endregion
|
|
133
|
+
export { businessPlugin };
|
|
@@ -1 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
18
|
+
const require_basic = require('../basic-DsQqC5nZ.cjs');
|
|
19
|
+
const require_primitives = require('../primitives-CtuSNmV7.cjs');
|
|
20
|
+
const require_non_primitives = require('../non-primitives-D9zxCwX8.cjs');
|
|
21
|
+
|
|
22
|
+
//#region src/plugins/dateRangePlugin.ts
|
|
23
|
+
/** * Plugin to inject `getDatesInRange` related method */
|
|
24
|
+
const dateRangePlugin = ($Chronos) => {
|
|
25
|
+
const { internalDate: $Date, cast, withOrigin, offset } = $Chronos[require_basic.INTERNALS];
|
|
26
|
+
$Chronos.prototype.getDatesInRange = function(options) {
|
|
27
|
+
let startDate = this.clone(), endDate = this.addWeeks(4);
|
|
28
|
+
const { format = "local", onlyDays, skipDays, roundDate = false } = options ?? {};
|
|
29
|
+
if (options) {
|
|
30
|
+
if ("from" in options || "to" in options) {
|
|
31
|
+
if (options?.from) startDate = cast(options.from);
|
|
32
|
+
if (options?.to) endDate = cast(options.to);
|
|
33
|
+
} else if ("span" in options || "unit" in options) {
|
|
34
|
+
const { span = 4, unit = "week" } = options;
|
|
35
|
+
endDate = startDate.add(span, unit);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (roundDate) {
|
|
39
|
+
startDate = startDate.startOf("day");
|
|
40
|
+
endDate = endDate.startOf("day");
|
|
41
|
+
}
|
|
42
|
+
const skippedDays = require_non_primitives.isValidArray(onlyDays) ? onlyDays : require_non_primitives.isValidArray(skipDays) ? skipDays : [];
|
|
43
|
+
const skipSet = new Set(skippedDays.map((day) => require_primitives.isNumber(day) ? day : require_basic.DAYS.indexOf(day)));
|
|
44
|
+
const dates = [];
|
|
45
|
+
const startTime = $Date(startDate).getTime();
|
|
46
|
+
const endTime = $Date(endDate).getTime();
|
|
47
|
+
const step = (startTime <= endTime ? 1 : -1) * require_basic.MS_PER_DAY;
|
|
48
|
+
const totalDays = Math.floor(Math.abs(endTime - startTime) / require_basic.MS_PER_DAY);
|
|
49
|
+
for (let i = 0; i <= totalDays; i++) {
|
|
50
|
+
const ts = startTime + i * step;
|
|
51
|
+
const wDay = new Date(ts).getDay();
|
|
52
|
+
if (require_non_primitives.isValidArray(onlyDays) ? skipSet.has(wDay) : !skipSet.has(wDay)) {
|
|
53
|
+
const chr = withOrigin(new $Chronos(ts), "clone", offset(this), startDate.timeZoneName, startDate.timeZoneId, startDate.$tzTracker);
|
|
54
|
+
dates.push(format === "local" ? chr.toLocalISOString() : chr.toISOString());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return dates;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
exports.dateRangePlugin = dateRangePlugin;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { C as $Chronos, I as RangeWithDates, L as RelativeDateRange, mt as ISODateTimeString } from "../types-CdmsXbU_.cjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/dateRangePlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -34,7 +50,7 @@ declare module 'chronos-date' {
|
|
|
34
50
|
* new Chronos().getDatesInRange({ span: 2, unit: 'day', format: 'utc' });
|
|
35
51
|
* // → ['2025-06-16T00:00:00.000Z', '2025-06-17T00:00:00.000Z']
|
|
36
52
|
*/
|
|
37
|
-
getDatesInRange(options?: RangeWithDates):
|
|
53
|
+
getDatesInRange(options?: RangeWithDates): ISODateTimeString<'local' | 'utc'>[];
|
|
38
54
|
/**
|
|
39
55
|
* @instance Returns an array of ISO date-time strings within a specific date range.
|
|
40
56
|
*
|
|
@@ -62,7 +78,7 @@ declare module 'chronos-date' {
|
|
|
62
78
|
* new Chronos().getDatesInRange({ from: '2025-01-01', to: '2025-01-03' });
|
|
63
79
|
* // → ['2025-01-01T00:00:00+06:00', '2025-01-02T00:00:00+06:00', '2025-01-03T00:00:00+06:00']
|
|
64
80
|
*/
|
|
65
|
-
getDatesInRange(options?: RelativeDateRange):
|
|
81
|
+
getDatesInRange(options?: RelativeDateRange): ISODateTimeString<'local' | 'utc'>[];
|
|
66
82
|
}
|
|
67
83
|
}
|
|
68
84
|
/** * Plugin to inject `getDatesInRange` related method */
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { C as $Chronos, I as RangeWithDates, L as RelativeDateRange, mt as ISODateTimeString } from "../types-Cb4gxrgJ.mjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/dateRangePlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -34,7 +50,7 @@ declare module 'chronos-date' {
|
|
|
34
50
|
* new Chronos().getDatesInRange({ span: 2, unit: 'day', format: 'utc' });
|
|
35
51
|
* // → ['2025-06-16T00:00:00.000Z', '2025-06-17T00:00:00.000Z']
|
|
36
52
|
*/
|
|
37
|
-
getDatesInRange(options?: RangeWithDates):
|
|
53
|
+
getDatesInRange(options?: RangeWithDates): ISODateTimeString<'local' | 'utc'>[];
|
|
38
54
|
/**
|
|
39
55
|
* @instance Returns an array of ISO date-time strings within a specific date range.
|
|
40
56
|
*
|
|
@@ -62,7 +78,7 @@ declare module 'chronos-date' {
|
|
|
62
78
|
* new Chronos().getDatesInRange({ from: '2025-01-01', to: '2025-01-03' });
|
|
63
79
|
* // → ['2025-01-01T00:00:00+06:00', '2025-01-02T00:00:00+06:00', '2025-01-03T00:00:00+06:00']
|
|
64
80
|
*/
|
|
65
|
-
getDatesInRange(options?: RelativeDateRange):
|
|
81
|
+
getDatesInRange(options?: RelativeDateRange): ISODateTimeString<'local' | 'utc'>[];
|
|
66
82
|
}
|
|
67
83
|
}
|
|
68
84
|
/** * Plugin to inject `getDatesInRange` related method */
|
|
@@ -1 +1,61 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { o as DAYS, s as INTERNALS, u as MS_PER_DAY } from "../basic-DqKyujoj.mjs";
|
|
18
|
+
import { r as isNumber } from "../primitives-dXzXlzJw.mjs";
|
|
19
|
+
import { a as isValidArray } from "../non-primitives-DBtomDty.mjs";
|
|
20
|
+
|
|
21
|
+
//#region src/plugins/dateRangePlugin.ts
|
|
22
|
+
/** * Plugin to inject `getDatesInRange` related method */
|
|
23
|
+
const dateRangePlugin = ($Chronos) => {
|
|
24
|
+
const { internalDate: $Date, cast, withOrigin, offset } = $Chronos[INTERNALS];
|
|
25
|
+
$Chronos.prototype.getDatesInRange = function(options) {
|
|
26
|
+
let startDate = this.clone(), endDate = this.addWeeks(4);
|
|
27
|
+
const { format = "local", onlyDays, skipDays, roundDate = false } = options ?? {};
|
|
28
|
+
if (options) {
|
|
29
|
+
if ("from" in options || "to" in options) {
|
|
30
|
+
if (options?.from) startDate = cast(options.from);
|
|
31
|
+
if (options?.to) endDate = cast(options.to);
|
|
32
|
+
} else if ("span" in options || "unit" in options) {
|
|
33
|
+
const { span = 4, unit = "week" } = options;
|
|
34
|
+
endDate = startDate.add(span, unit);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (roundDate) {
|
|
38
|
+
startDate = startDate.startOf("day");
|
|
39
|
+
endDate = endDate.startOf("day");
|
|
40
|
+
}
|
|
41
|
+
const skippedDays = isValidArray(onlyDays) ? onlyDays : isValidArray(skipDays) ? skipDays : [];
|
|
42
|
+
const skipSet = new Set(skippedDays.map((day) => isNumber(day) ? day : DAYS.indexOf(day)));
|
|
43
|
+
const dates = [];
|
|
44
|
+
const startTime = $Date(startDate).getTime();
|
|
45
|
+
const endTime = $Date(endDate).getTime();
|
|
46
|
+
const step = (startTime <= endTime ? 1 : -1) * MS_PER_DAY;
|
|
47
|
+
const totalDays = Math.floor(Math.abs(endTime - startTime) / MS_PER_DAY);
|
|
48
|
+
for (let i = 0; i <= totalDays; i++) {
|
|
49
|
+
const ts = startTime + i * step;
|
|
50
|
+
const wDay = new Date(ts).getDay();
|
|
51
|
+
if (isValidArray(onlyDays) ? skipSet.has(wDay) : !skipSet.has(wDay)) {
|
|
52
|
+
const chr = withOrigin(new $Chronos(ts), "clone", offset(this), startDate.timeZoneName, startDate.timeZoneId, startDate.$tzTracker);
|
|
53
|
+
dates.push(format === "local" ? chr.toLocalISOString() : chr.toISOString());
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return dates;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { dateRangePlugin };
|
|
@@ -1 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
18
|
+
const require_basic = require('../basic-DsQqC5nZ.cjs');
|
|
19
|
+
const require_non_primitives = require('../non-primitives-D9zxCwX8.cjs');
|
|
20
|
+
|
|
21
|
+
//#region src/plugins/dayPartPlugin.ts
|
|
22
|
+
/** * Plugin to inject `getPartOfDay` method */
|
|
23
|
+
const dayPartPlugin = ($Chronos) => {
|
|
24
|
+
$Chronos.prototype.getPartOfDay = function(config) {
|
|
25
|
+
const hour = this.hour;
|
|
26
|
+
const ranges = {
|
|
27
|
+
...require_basic.DATE_PART_RANGES,
|
|
28
|
+
...require_non_primitives.isNotEmptyObject(config) && config
|
|
29
|
+
};
|
|
30
|
+
for (const [part, [start, end]] of Object.entries(ranges)) {
|
|
31
|
+
const from = Number(start);
|
|
32
|
+
const to = Number(end);
|
|
33
|
+
if (from <= to) {
|
|
34
|
+
if (hour >= from && hour <= to) return part;
|
|
35
|
+
} else if (hour >= from || hour <= to) return part;
|
|
36
|
+
}
|
|
37
|
+
return "night";
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.dayPartPlugin = dayPartPlugin;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { C as $Chronos, c as DayPart, l as DayPartConfig } from "../types-CdmsXbU_.cjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/dayPartPlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { C as $Chronos, c as DayPart, l as DayPartConfig } from "../types-Cb4gxrgJ.mjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/dayPartPlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -1 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { a as DATE_PART_RANGES } from "../basic-DqKyujoj.mjs";
|
|
18
|
+
import { n as isNotEmptyObject } from "../non-primitives-DBtomDty.mjs";
|
|
19
|
+
|
|
20
|
+
//#region src/plugins/dayPartPlugin.ts
|
|
21
|
+
/** * Plugin to inject `getPartOfDay` method */
|
|
22
|
+
const dayPartPlugin = ($Chronos) => {
|
|
23
|
+
$Chronos.prototype.getPartOfDay = function(config) {
|
|
24
|
+
const hour = this.hour;
|
|
25
|
+
const ranges = {
|
|
26
|
+
...DATE_PART_RANGES,
|
|
27
|
+
...isNotEmptyObject(config) && config
|
|
28
|
+
};
|
|
29
|
+
for (const [part, [start, end]] of Object.entries(ranges)) {
|
|
30
|
+
const from = Number(start);
|
|
31
|
+
const to = Number(end);
|
|
32
|
+
if (from <= to) {
|
|
33
|
+
if (hour >= from && hour <= to) return part;
|
|
34
|
+
} else if (hour >= from || hour <= to) return part;
|
|
35
|
+
}
|
|
36
|
+
return "night";
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { dayPartPlugin };
|
|
@@ -1 +1,107 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
18
|
+
const require_basic = require('../basic-DsQqC5nZ.cjs');
|
|
19
|
+
|
|
20
|
+
//#region src/plugins/durationPlugin.ts
|
|
21
|
+
/** * Plugin to inject `duration` related methods */
|
|
22
|
+
const durationPlugin = ($Chronos) => {
|
|
23
|
+
const { toNewDate } = $Chronos[require_basic.INTERNALS];
|
|
24
|
+
/**
|
|
25
|
+
* @private Normalizes duration values based on sign and `absolute` flag.
|
|
26
|
+
* @param result The raw time breakdown to normalize.
|
|
27
|
+
* @param absolute If true, ensures all values are positive.
|
|
28
|
+
* @param isFuture Whether the duration was forward (true) or backward (false).
|
|
29
|
+
* @returns The normalized duration object.
|
|
30
|
+
*/
|
|
31
|
+
const _normalizeDuration = (result, absolute, isFuture) => {
|
|
32
|
+
const entries = Object.entries(result);
|
|
33
|
+
const updated = { ...result };
|
|
34
|
+
if (!absolute && !isFuture) {
|
|
35
|
+
for (const [key, value] of entries) if (value !== 0) updated[key] = value * -1;
|
|
36
|
+
} else if (absolute) for (const [key, value] of entries) updated[key] = Math.abs(value);
|
|
37
|
+
return updated;
|
|
38
|
+
};
|
|
39
|
+
$Chronos.prototype.duration = function(toTime, absolute = true) {
|
|
40
|
+
const now = this.toDate();
|
|
41
|
+
const target = toNewDate(this, toTime);
|
|
42
|
+
const isFuture = target > now;
|
|
43
|
+
const from = isFuture ? now : target;
|
|
44
|
+
const to = isFuture ? target : now;
|
|
45
|
+
/** Get difference between `to` and `from` for specific unit */
|
|
46
|
+
const _getDiff = (suffix) => {
|
|
47
|
+
return to[`get${suffix}`]() - from[`get${suffix}`]();
|
|
48
|
+
};
|
|
49
|
+
let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
|
|
50
|
+
if (ms < 0) {
|
|
51
|
+
ms += 1e3;
|
|
52
|
+
s--;
|
|
53
|
+
}
|
|
54
|
+
if (s < 0) {
|
|
55
|
+
s += 60;
|
|
56
|
+
m--;
|
|
57
|
+
}
|
|
58
|
+
if (m < 0) {
|
|
59
|
+
m += 60;
|
|
60
|
+
h--;
|
|
61
|
+
}
|
|
62
|
+
if (h < 0) {
|
|
63
|
+
h += 24;
|
|
64
|
+
d--;
|
|
65
|
+
}
|
|
66
|
+
if (d < 0) {
|
|
67
|
+
const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
|
|
68
|
+
d += prevMonth.getDate();
|
|
69
|
+
mo--;
|
|
70
|
+
}
|
|
71
|
+
if (mo < 0) {
|
|
72
|
+
mo += 12;
|
|
73
|
+
y--;
|
|
74
|
+
}
|
|
75
|
+
return _normalizeDuration({
|
|
76
|
+
years: y,
|
|
77
|
+
months: mo,
|
|
78
|
+
days: d,
|
|
79
|
+
hours: h,
|
|
80
|
+
minutes: m,
|
|
81
|
+
seconds: s,
|
|
82
|
+
milliseconds: ms
|
|
83
|
+
}, absolute, isFuture);
|
|
84
|
+
};
|
|
85
|
+
$Chronos.prototype.durationString = function(options) {
|
|
86
|
+
const { toTime, absolute = true, maxUnits = 7, separator = ", ", style = "full", showZero = false } = options ?? {};
|
|
87
|
+
const duration = this.duration(toTime, absolute);
|
|
88
|
+
const units = {
|
|
89
|
+
years: "y",
|
|
90
|
+
months: "mo",
|
|
91
|
+
days: "d",
|
|
92
|
+
hours: "h",
|
|
93
|
+
minutes: "m",
|
|
94
|
+
seconds: "s",
|
|
95
|
+
milliseconds: "ms"
|
|
96
|
+
};
|
|
97
|
+
const _formatUnit = (unit, value) => {
|
|
98
|
+
if (style === "short") return `${value}${units[unit]}`;
|
|
99
|
+
return `${value} ${Math.abs(value) === 1 ? unit.slice(0, -1) : unit}`;
|
|
100
|
+
};
|
|
101
|
+
const parts = Object.entries(duration).filter(([_, value]) => showZero || Math.abs(value) > 0).slice(0, maxUnits).map(([unit, value]) => _formatUnit(unit, value));
|
|
102
|
+
return parts.length ? parts.join(separator) : style === "short" ? "0s" : "0 seconds";
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
exports.durationPlugin = durationPlugin;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { C as $Chronos, D as ChronosInput, d as DurationOptions, g as TimeDuration } from "../types-CdmsXbU_.cjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/durationPlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { C as $Chronos, D as ChronosInput, d as DurationOptions, g as TimeDuration } from "../types-Cb4gxrgJ.mjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/durationPlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|