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,90 @@
|
|
|
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/relativeTimePlugin.ts
|
|
21
|
+
/** * Plugin to inject `relative time` related methods */
|
|
22
|
+
const relativeTimePlugin = ($Chronos) => {
|
|
23
|
+
const { toNewDate } = $Chronos[require_basic.INTERNALS];
|
|
24
|
+
$Chronos.prototype.getRelativeYear = function(time) {
|
|
25
|
+
const $date = this.toDate();
|
|
26
|
+
const now = toNewDate(this, time);
|
|
27
|
+
let years = $date.getFullYear() - now.getFullYear();
|
|
28
|
+
if (now.getMonth() < $date.getMonth() || now.getMonth() === $date.getMonth() && now.getDate() < $date.getDate()) years--;
|
|
29
|
+
return years;
|
|
30
|
+
};
|
|
31
|
+
$Chronos.prototype.getRelativeMonth = function(time) {
|
|
32
|
+
const $date = this.toDate();
|
|
33
|
+
const now = toNewDate(this, time);
|
|
34
|
+
let months = ($date.getFullYear() - now.getFullYear()) * 12 + ($date.getMonth() - now.getMonth());
|
|
35
|
+
if (now.getDate() < $date.getDate()) months--;
|
|
36
|
+
return months;
|
|
37
|
+
};
|
|
38
|
+
$Chronos.prototype.getRelativeWeek = function(time) {
|
|
39
|
+
const relativeDays = this.getRelativeDay(time);
|
|
40
|
+
return Math.floor(relativeDays / 7);
|
|
41
|
+
};
|
|
42
|
+
$Chronos.prototype.getRelativeDay = function(time) {
|
|
43
|
+
const now = toNewDate(this, time);
|
|
44
|
+
now.setHours(0, 0, 0, 0);
|
|
45
|
+
const $date = new Date(this.toDate());
|
|
46
|
+
$date.setHours(0, 0, 0, 0);
|
|
47
|
+
const diffTime = $date.getTime() - now.getTime();
|
|
48
|
+
return Math.floor(diffTime / (1e3 * 60 * 60 * 24));
|
|
49
|
+
};
|
|
50
|
+
$Chronos.prototype.getRelativeHour = function(time) {
|
|
51
|
+
const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
52
|
+
return Math.floor(diff / (1e3 * 60 * 60));
|
|
53
|
+
};
|
|
54
|
+
$Chronos.prototype.getRelativeMinute = function(time) {
|
|
55
|
+
const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
56
|
+
return Math.floor(diff / (1e3 * 60));
|
|
57
|
+
};
|
|
58
|
+
$Chronos.prototype.getRelativeSecond = function(time) {
|
|
59
|
+
const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
60
|
+
return Math.floor(diff / 1e3);
|
|
61
|
+
};
|
|
62
|
+
$Chronos.prototype.getRelativeMilliSecond = function(time) {
|
|
63
|
+
return this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
64
|
+
};
|
|
65
|
+
$Chronos.prototype.compare = function(unit = "minute", time) {
|
|
66
|
+
switch (unit) {
|
|
67
|
+
case "year": return this.getRelativeYear(time);
|
|
68
|
+
case "month": return this.getRelativeMonth(time);
|
|
69
|
+
case "day": return this.getRelativeDay(time);
|
|
70
|
+
case "week": return this.getRelativeWeek(time);
|
|
71
|
+
case "hour": return this.getRelativeHour(time);
|
|
72
|
+
case "minute": return this.getRelativeMinute(time);
|
|
73
|
+
case "second": return this.getRelativeSecond(time);
|
|
74
|
+
case "millisecond": return this.getRelativeMilliSecond(time);
|
|
75
|
+
default: throw new RangeError(`Unsupported time unit: ${unit}`);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
$Chronos.prototype.isToday = function() {
|
|
79
|
+
return this.getRelativeDay() === 0;
|
|
80
|
+
};
|
|
81
|
+
$Chronos.prototype.isTomorrow = function() {
|
|
82
|
+
return this.getRelativeDay() === 1;
|
|
83
|
+
};
|
|
84
|
+
$Chronos.prototype.isYesterday = function() {
|
|
85
|
+
return this.getRelativeDay() === -1;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
exports.relativeTimePlugin = relativeTimePlugin;
|
|
@@ -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, Tt as TimeUnit } from "../types-CdmsXbU_.cjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/relativeTimePlugin.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, Tt as TimeUnit } from "../types-Cb4gxrgJ.mjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/relativeTimePlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -1 +1,89 @@
|
|
|
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
|
+
|
|
19
|
+
//#region src/plugins/relativeTimePlugin.ts
|
|
20
|
+
/** * Plugin to inject `relative time` related methods */
|
|
21
|
+
const relativeTimePlugin = ($Chronos) => {
|
|
22
|
+
const { toNewDate } = $Chronos[INTERNALS];
|
|
23
|
+
$Chronos.prototype.getRelativeYear = function(time) {
|
|
24
|
+
const $date = this.toDate();
|
|
25
|
+
const now = toNewDate(this, time);
|
|
26
|
+
let years = $date.getFullYear() - now.getFullYear();
|
|
27
|
+
if (now.getMonth() < $date.getMonth() || now.getMonth() === $date.getMonth() && now.getDate() < $date.getDate()) years--;
|
|
28
|
+
return years;
|
|
29
|
+
};
|
|
30
|
+
$Chronos.prototype.getRelativeMonth = function(time) {
|
|
31
|
+
const $date = this.toDate();
|
|
32
|
+
const now = toNewDate(this, time);
|
|
33
|
+
let months = ($date.getFullYear() - now.getFullYear()) * 12 + ($date.getMonth() - now.getMonth());
|
|
34
|
+
if (now.getDate() < $date.getDate()) months--;
|
|
35
|
+
return months;
|
|
36
|
+
};
|
|
37
|
+
$Chronos.prototype.getRelativeWeek = function(time) {
|
|
38
|
+
const relativeDays = this.getRelativeDay(time);
|
|
39
|
+
return Math.floor(relativeDays / 7);
|
|
40
|
+
};
|
|
41
|
+
$Chronos.prototype.getRelativeDay = function(time) {
|
|
42
|
+
const now = toNewDate(this, time);
|
|
43
|
+
now.setHours(0, 0, 0, 0);
|
|
44
|
+
const $date = new Date(this.toDate());
|
|
45
|
+
$date.setHours(0, 0, 0, 0);
|
|
46
|
+
const diffTime = $date.getTime() - now.getTime();
|
|
47
|
+
return Math.floor(diffTime / (1e3 * 60 * 60 * 24));
|
|
48
|
+
};
|
|
49
|
+
$Chronos.prototype.getRelativeHour = function(time) {
|
|
50
|
+
const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
51
|
+
return Math.floor(diff / (1e3 * 60 * 60));
|
|
52
|
+
};
|
|
53
|
+
$Chronos.prototype.getRelativeMinute = function(time) {
|
|
54
|
+
const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
55
|
+
return Math.floor(diff / (1e3 * 60));
|
|
56
|
+
};
|
|
57
|
+
$Chronos.prototype.getRelativeSecond = function(time) {
|
|
58
|
+
const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
59
|
+
return Math.floor(diff / 1e3);
|
|
60
|
+
};
|
|
61
|
+
$Chronos.prototype.getRelativeMilliSecond = function(time) {
|
|
62
|
+
return this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
63
|
+
};
|
|
64
|
+
$Chronos.prototype.compare = function(unit = "minute", time) {
|
|
65
|
+
switch (unit) {
|
|
66
|
+
case "year": return this.getRelativeYear(time);
|
|
67
|
+
case "month": return this.getRelativeMonth(time);
|
|
68
|
+
case "day": return this.getRelativeDay(time);
|
|
69
|
+
case "week": return this.getRelativeWeek(time);
|
|
70
|
+
case "hour": return this.getRelativeHour(time);
|
|
71
|
+
case "minute": return this.getRelativeMinute(time);
|
|
72
|
+
case "second": return this.getRelativeSecond(time);
|
|
73
|
+
case "millisecond": return this.getRelativeMilliSecond(time);
|
|
74
|
+
default: throw new RangeError(`Unsupported time unit: ${unit}`);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
$Chronos.prototype.isToday = function() {
|
|
78
|
+
return this.getRelativeDay() === 0;
|
|
79
|
+
};
|
|
80
|
+
$Chronos.prototype.isTomorrow = function() {
|
|
81
|
+
return this.getRelativeDay() === 1;
|
|
82
|
+
};
|
|
83
|
+
$Chronos.prototype.isYesterday = function() {
|
|
84
|
+
return this.getRelativeDay() === -1;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
export { relativeTimePlugin };
|
|
@@ -1 +1,85 @@
|
|
|
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_utilities = require('../utilities-CpF3uys3.cjs');
|
|
20
|
+
|
|
21
|
+
//#region src/plugins/roundPlugin.ts
|
|
22
|
+
/** * Plugin to inject `round` method */
|
|
23
|
+
const roundPlugin = ($Chronos) => {
|
|
24
|
+
const { internalDate, withOrigin, offset } = $Chronos[require_basic.INTERNALS];
|
|
25
|
+
$Chronos.prototype.round = function(unit, nearest = 1) {
|
|
26
|
+
const date = new Date(internalDate(this));
|
|
27
|
+
switch (unit) {
|
|
28
|
+
case "millisecond": {
|
|
29
|
+
const rounded = require_utilities.roundToNearest(date.getMilliseconds(), nearest);
|
|
30
|
+
date.setMilliseconds(rounded);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case "second": {
|
|
34
|
+
const rounded = require_utilities.roundToNearest(date.getSeconds() + date.getMilliseconds() / 1e3, nearest);
|
|
35
|
+
date.setSeconds(rounded, 0);
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
case "minute": {
|
|
39
|
+
const rounded = require_utilities.roundToNearest(date.getMinutes() + date.getSeconds() / 60 + date.getMilliseconds() / 6e4, nearest);
|
|
40
|
+
date.setMinutes(rounded, 0, 0);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case "hour": {
|
|
44
|
+
const rounded = require_utilities.roundToNearest(date.getHours() + date.getMinutes() / 60 + date.getSeconds() / 3600 + date.getMilliseconds() / 36e5, nearest);
|
|
45
|
+
date.setHours(rounded, 0, 0, 0);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case "day": {
|
|
49
|
+
const rounded = require_utilities.roundToNearest(date.getDate() + (date.getHours() / 24 + date.getMinutes() / 1440 + date.getSeconds() / 86400 + date.getMilliseconds() / require_basic.MS_PER_DAY), nearest);
|
|
50
|
+
date.setDate(rounded);
|
|
51
|
+
date.setHours(0, 0, 0, 0);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case "week": {
|
|
55
|
+
const offsetToMonday = (date.getDay() + 6) % 7;
|
|
56
|
+
const startOfWeek = new Date(date);
|
|
57
|
+
startOfWeek.setDate(startOfWeek.getDate() - offsetToMonday);
|
|
58
|
+
startOfWeek.setHours(0, 0, 0, 0);
|
|
59
|
+
const endOfWeek = new Date(startOfWeek);
|
|
60
|
+
endOfWeek.setDate(endOfWeek.getDate() + 7);
|
|
61
|
+
const diffToStart = Math.abs(date.getTime() - startOfWeek.getTime());
|
|
62
|
+
return withOrigin(new $Chronos(Math.abs(endOfWeek.getTime() - date.getTime()) < diffToStart ? endOfWeek : startOfWeek), "round");
|
|
63
|
+
}
|
|
64
|
+
case "month": {
|
|
65
|
+
const roundedMonth = require_utilities.roundToNearest(date.getMonth() + date.getDate() / this.lastDateOfMonth, nearest);
|
|
66
|
+
date.setMonth(roundedMonth, 1);
|
|
67
|
+
date.setHours(0, 0, 0, 0);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case "year": {
|
|
71
|
+
const dayOfYear = Math.floor((date.getTime() - new Date(date.getFullYear(), 0, 1).getTime()) / require_basic.MS_PER_DAY);
|
|
72
|
+
const totalDays = new Date(date.getFullYear(), 1, 29).getDate() === 29 ? 366 : 365;
|
|
73
|
+
const roundedYear = require_utilities.roundToNearest(date.getFullYear() + dayOfYear / totalDays, nearest);
|
|
74
|
+
date.setFullYear(roundedYear, 0, 1);
|
|
75
|
+
date.setHours(0, 0, 0, 0);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
default: return this;
|
|
79
|
+
}
|
|
80
|
+
return withOrigin(new $Chronos(date), "round", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
exports.roundPlugin = roundPlugin;
|
|
@@ -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, Tt as TimeUnit } from "../types-CdmsXbU_.cjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/roundPlugin.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, Tt as TimeUnit } from "../types-Cb4gxrgJ.mjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/roundPlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -1 +1,84 @@
|
|
|
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, u as MS_PER_DAY } from "../basic-DqKyujoj.mjs";
|
|
18
|
+
import { r as roundToNearest } from "../utilities-BKtVo78T.mjs";
|
|
19
|
+
|
|
20
|
+
//#region src/plugins/roundPlugin.ts
|
|
21
|
+
/** * Plugin to inject `round` method */
|
|
22
|
+
const roundPlugin = ($Chronos) => {
|
|
23
|
+
const { internalDate, withOrigin, offset } = $Chronos[INTERNALS];
|
|
24
|
+
$Chronos.prototype.round = function(unit, nearest = 1) {
|
|
25
|
+
const date = new Date(internalDate(this));
|
|
26
|
+
switch (unit) {
|
|
27
|
+
case "millisecond": {
|
|
28
|
+
const rounded = roundToNearest(date.getMilliseconds(), nearest);
|
|
29
|
+
date.setMilliseconds(rounded);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case "second": {
|
|
33
|
+
const rounded = roundToNearest(date.getSeconds() + date.getMilliseconds() / 1e3, nearest);
|
|
34
|
+
date.setSeconds(rounded, 0);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case "minute": {
|
|
38
|
+
const rounded = roundToNearest(date.getMinutes() + date.getSeconds() / 60 + date.getMilliseconds() / 6e4, nearest);
|
|
39
|
+
date.setMinutes(rounded, 0, 0);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case "hour": {
|
|
43
|
+
const rounded = roundToNearest(date.getHours() + date.getMinutes() / 60 + date.getSeconds() / 3600 + date.getMilliseconds() / 36e5, nearest);
|
|
44
|
+
date.setHours(rounded, 0, 0, 0);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "day": {
|
|
48
|
+
const rounded = roundToNearest(date.getDate() + (date.getHours() / 24 + date.getMinutes() / 1440 + date.getSeconds() / 86400 + date.getMilliseconds() / MS_PER_DAY), nearest);
|
|
49
|
+
date.setDate(rounded);
|
|
50
|
+
date.setHours(0, 0, 0, 0);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case "week": {
|
|
54
|
+
const offsetToMonday = (date.getDay() + 6) % 7;
|
|
55
|
+
const startOfWeek = new Date(date);
|
|
56
|
+
startOfWeek.setDate(startOfWeek.getDate() - offsetToMonday);
|
|
57
|
+
startOfWeek.setHours(0, 0, 0, 0);
|
|
58
|
+
const endOfWeek = new Date(startOfWeek);
|
|
59
|
+
endOfWeek.setDate(endOfWeek.getDate() + 7);
|
|
60
|
+
const diffToStart = Math.abs(date.getTime() - startOfWeek.getTime());
|
|
61
|
+
return withOrigin(new $Chronos(Math.abs(endOfWeek.getTime() - date.getTime()) < diffToStart ? endOfWeek : startOfWeek), "round");
|
|
62
|
+
}
|
|
63
|
+
case "month": {
|
|
64
|
+
const roundedMonth = roundToNearest(date.getMonth() + date.getDate() / this.lastDateOfMonth, nearest);
|
|
65
|
+
date.setMonth(roundedMonth, 1);
|
|
66
|
+
date.setHours(0, 0, 0, 0);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "year": {
|
|
70
|
+
const dayOfYear = Math.floor((date.getTime() - new Date(date.getFullYear(), 0, 1).getTime()) / MS_PER_DAY);
|
|
71
|
+
const totalDays = new Date(date.getFullYear(), 1, 29).getDate() === 29 ? 366 : 365;
|
|
72
|
+
const roundedYear = roundToNearest(date.getFullYear() + dayOfYear / totalDays, nearest);
|
|
73
|
+
date.setFullYear(roundedYear, 0, 1);
|
|
74
|
+
date.setHours(0, 0, 0, 0);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
default: return this;
|
|
78
|
+
}
|
|
79
|
+
return withOrigin(new $Chronos(date), "round", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
export { roundPlugin };
|
|
@@ -1 +1,47 @@
|
|
|
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_seasons = require('../seasons-B7kK88zq.cjs');
|
|
19
|
+
|
|
20
|
+
//#region src/plugins/seasonPlugin.ts
|
|
21
|
+
/** * Plugin to inject `season`/`getSeasonName` method */
|
|
22
|
+
const seasonPlugin = ($Chronos) => {
|
|
23
|
+
$Chronos.prototype.season = function(options) {
|
|
24
|
+
const { preset = "default" } = options ?? {};
|
|
25
|
+
const seasonSet = options?.seasons ?? require_seasons.SEASON_PRESETS[preset];
|
|
26
|
+
const dateStr = this.format("MM-DD");
|
|
27
|
+
for (const { name, boundary } of seasonSet) if ("startDate" in boundary && "endDate" in boundary) {
|
|
28
|
+
const start = boundary.startDate;
|
|
29
|
+
const end = boundary.endDate;
|
|
30
|
+
if (start <= end) {
|
|
31
|
+
if (dateStr >= start && dateStr <= end) return name;
|
|
32
|
+
} else if (dateStr >= start || dateStr <= end) return name;
|
|
33
|
+
} else if ("startMonth" in boundary && "endMonth" in boundary) {
|
|
34
|
+
const { startMonth, endMonth } = boundary;
|
|
35
|
+
if (startMonth <= endMonth) {
|
|
36
|
+
if (this.month >= startMonth && this.month <= endMonth) return name;
|
|
37
|
+
} else if (this.month >= startMonth || this.month <= endMonth) return name;
|
|
38
|
+
}
|
|
39
|
+
return "Unknown";
|
|
40
|
+
};
|
|
41
|
+
$Chronos.prototype.getSeasonName = function(options) {
|
|
42
|
+
return this.season(options);
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.seasonPlugin = seasonPlugin;
|
|
@@ -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, m as SeasonOptions } from "../types-CdmsXbU_.cjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/seasonPlugin.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, m as SeasonOptions } from "../types-Cb4gxrgJ.mjs";
|
|
2
18
|
|
|
3
19
|
//#region src/plugins/seasonPlugin.d.ts
|
|
4
20
|
declare module 'chronos-date' {
|
|
@@ -1 +1,46 @@
|
|
|
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 { u as SEASON_PRESETS } from "../seasons-Cq3ah3pV.mjs";
|
|
18
|
+
|
|
19
|
+
//#region src/plugins/seasonPlugin.ts
|
|
20
|
+
/** * Plugin to inject `season`/`getSeasonName` method */
|
|
21
|
+
const seasonPlugin = ($Chronos) => {
|
|
22
|
+
$Chronos.prototype.season = function(options) {
|
|
23
|
+
const { preset = "default" } = options ?? {};
|
|
24
|
+
const seasonSet = options?.seasons ?? SEASON_PRESETS[preset];
|
|
25
|
+
const dateStr = this.format("MM-DD");
|
|
26
|
+
for (const { name, boundary } of seasonSet) if ("startDate" in boundary && "endDate" in boundary) {
|
|
27
|
+
const start = boundary.startDate;
|
|
28
|
+
const end = boundary.endDate;
|
|
29
|
+
if (start <= end) {
|
|
30
|
+
if (dateStr >= start && dateStr <= end) return name;
|
|
31
|
+
} else if (dateStr >= start || dateStr <= end) return name;
|
|
32
|
+
} else if ("startMonth" in boundary && "endMonth" in boundary) {
|
|
33
|
+
const { startMonth, endMonth } = boundary;
|
|
34
|
+
if (startMonth <= endMonth) {
|
|
35
|
+
if (this.month >= startMonth && this.month <= endMonth) return name;
|
|
36
|
+
} else if (this.month >= startMonth || this.month <= endMonth) return name;
|
|
37
|
+
}
|
|
38
|
+
return "Unknown";
|
|
39
|
+
};
|
|
40
|
+
$Chronos.prototype.getSeasonName = function(options) {
|
|
41
|
+
return this.season(options);
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { seasonPlugin };
|