chronos-date 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/basic-DIp_pxR2.cjs +450 -0
- package/dist/basic-Dputob9z.mjs +366 -0
- package/dist/constants.cjs +27 -1
- package/dist/constants.mjs +5 -1
- package/dist/convert-CNVL-mop.mjs +22 -0
- package/dist/convert-dQuGWhVm.cjs +33 -0
- package/dist/greet-B8ZtypgG.cjs +40 -0
- package/dist/greet-B9j4afzD.mjs +35 -0
- package/dist/guards.cjs +119 -1
- package/dist/guards.mjs +110 -1
- package/dist/helpers-CrMc9iJZ.mjs +185 -0
- package/dist/helpers-M_SfAbAv.cjs +262 -0
- package/dist/index.cjs +1461 -1
- package/dist/index.mjs +1458 -1
- package/dist/non-primitives-CT4vszrX.cjs +52 -0
- package/dist/non-primitives-DrQfPj1r.mjs +22 -0
- package/dist/plugins/banglaPlugin.cjs +121 -1
- package/dist/plugins/banglaPlugin.d.cts +1 -1
- package/dist/plugins/banglaPlugin.d.mts +1 -1
- package/dist/plugins/banglaPlugin.mjs +120 -1
- package/dist/plugins/businessPlugin.cjs +118 -1
- package/dist/plugins/businessPlugin.d.cts +1 -1
- package/dist/plugins/businessPlugin.d.mts +1 -1
- package/dist/plugins/businessPlugin.mjs +117 -1
- package/dist/plugins/dateRangePlugin.cjs +46 -1
- package/dist/plugins/dateRangePlugin.d.cts +1 -1
- package/dist/plugins/dateRangePlugin.d.mts +1 -1
- package/dist/plugins/dateRangePlugin.mjs +45 -1
- package/dist/plugins/dayPartPlugin.cjs +26 -1
- package/dist/plugins/dayPartPlugin.d.cts +1 -1
- package/dist/plugins/dayPartPlugin.d.mts +1 -1
- package/dist/plugins/dayPartPlugin.mjs +25 -1
- package/dist/plugins/durationPlugin.cjs +91 -1
- package/dist/plugins/durationPlugin.d.cts +1 -1
- package/dist/plugins/durationPlugin.d.mts +1 -1
- package/dist/plugins/durationPlugin.mjs +90 -1
- package/dist/plugins/fromNowPlugin.cjs +80 -1
- package/dist/plugins/fromNowPlugin.d.cts +1 -1
- package/dist/plugins/fromNowPlugin.d.mts +1 -1
- package/dist/plugins/fromNowPlugin.mjs +79 -1
- package/dist/plugins/greetingPlugin.cjs +19 -1
- package/dist/plugins/greetingPlugin.d.cts +1 -1
- package/dist/plugins/greetingPlugin.d.mts +1 -1
- package/dist/plugins/greetingPlugin.mjs +18 -1
- package/dist/plugins/palindromePlugin.cjs +22 -1
- package/dist/plugins/palindromePlugin.d.cts +1 -1
- package/dist/plugins/palindromePlugin.d.mts +1 -1
- package/dist/plugins/palindromePlugin.mjs +21 -1
- package/dist/plugins/relativeTimePlugin.cjs +74 -1
- package/dist/plugins/relativeTimePlugin.d.cts +1 -1
- package/dist/plugins/relativeTimePlugin.d.mts +1 -1
- package/dist/plugins/relativeTimePlugin.mjs +73 -1
- package/dist/plugins/roundPlugin.cjs +69 -1
- package/dist/plugins/roundPlugin.d.cts +1 -1
- package/dist/plugins/roundPlugin.d.mts +1 -1
- package/dist/plugins/roundPlugin.mjs +68 -1
- package/dist/plugins/seasonPlugin.cjs +31 -1
- package/dist/plugins/seasonPlugin.d.cts +1 -1
- package/dist/plugins/seasonPlugin.d.mts +1 -1
- package/dist/plugins/seasonPlugin.mjs +30 -1
- package/dist/plugins/timeZonePlugin.cjs +139 -1
- package/dist/plugins/timeZonePlugin.d.cts +1 -1
- package/dist/plugins/timeZonePlugin.d.mts +1 -1
- package/dist/plugins/timeZonePlugin.mjs +138 -1
- package/dist/plugins/zodiacPlugin.cjs +51 -1
- package/dist/plugins/zodiacPlugin.d.cts +1 -1
- package/dist/plugins/zodiacPlugin.d.mts +1 -1
- package/dist/plugins/zodiacPlugin.mjs +50 -1
- package/dist/primitives-BME3_QrA.cjs +49 -0
- package/dist/primitives-DEt6I7Sy.mjs +19 -0
- package/dist/seasons-CHnjrIKK.mjs +352 -0
- package/dist/seasons-CcZicoe1.cjs +418 -0
- package/dist/timezone-BfBXeMK_.mjs +5573 -0
- package/dist/timezone-DYVJJYKz.cjs +5609 -0
- package/dist/types.mjs +1 -1
- package/dist/utilities-BU4MSYS7.mjs +43 -0
- package/dist/utilities-CGL7F6R9.cjs +72 -0
- package/dist/utilities-CtOZhIYv.mjs +241 -0
- package/dist/utilities-bXwTPJaD.cjs +318 -0
- package/dist/utils.cjs +76 -1
- package/dist/utils.mjs +44 -1
- package/package.json +1 -1
- 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,22 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_convert = require('../convert-dQuGWhVm.cjs');
|
|
3
|
+
|
|
4
|
+
//#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/string/guards.js
|
|
5
|
+
const isPalindrome = (input) => {
|
|
6
|
+
const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
7
|
+
return normalized === require_convert.reverseString(normalized);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/plugins/palindromePlugin.ts
|
|
12
|
+
/** * Plugin to inject `isPalindromeDate` method */
|
|
13
|
+
const palindromePlugin = ($Chronos) => {
|
|
14
|
+
$Chronos.prototype.isPalindromeDate = function(shortYear = false) {
|
|
15
|
+
const padded = this.formatStrict(shortYear ? "YY-MM-DD" : "YYYY-MM-DD");
|
|
16
|
+
const normal = this.formatStrict(shortYear ? "YY-M-D" : "YYYY-M-D");
|
|
17
|
+
return isPalindrome(padded) || isPalindrome(normal);
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.palindromePlugin = palindromePlugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos } from "../types-DPTQ_yLx.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/palindromePlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Checks if the current date is a palindrome in either padded or non-padded format.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos } from "../types-B2fgrJ86.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/palindromePlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Checks if the current date is a palindrome in either padded or non-padded format.
|
|
@@ -1 +1,21 @@
|
|
|
1
|
-
import{n as
|
|
1
|
+
import { n as reverseString } from "../convert-CNVL-mop.mjs";
|
|
2
|
+
|
|
3
|
+
//#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/string/guards.js
|
|
4
|
+
const isPalindrome = (input) => {
|
|
5
|
+
const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
6
|
+
return normalized === reverseString(normalized);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/plugins/palindromePlugin.ts
|
|
11
|
+
/** * Plugin to inject `isPalindromeDate` method */
|
|
12
|
+
const palindromePlugin = ($Chronos) => {
|
|
13
|
+
$Chronos.prototype.isPalindromeDate = function(shortYear = false) {
|
|
14
|
+
const padded = this.formatStrict(shortYear ? "YY-MM-DD" : "YYYY-MM-DD");
|
|
15
|
+
const normal = this.formatStrict(shortYear ? "YY-M-D" : "YYYY-M-D");
|
|
16
|
+
return isPalindrome(padded) || isPalindrome(normal);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { palindromePlugin };
|
|
@@ -1 +1,74 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_basic = require('../basic-DIp_pxR2.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/relativeTimePlugin.ts
|
|
5
|
+
/** * Plugin to inject `relative time` related methods */
|
|
6
|
+
const relativeTimePlugin = ($Chronos) => {
|
|
7
|
+
const { toNewDate } = $Chronos[require_basic.INTERNALS];
|
|
8
|
+
$Chronos.prototype.getRelativeYear = function(time) {
|
|
9
|
+
const $date = this.toDate();
|
|
10
|
+
const now = toNewDate(this, time);
|
|
11
|
+
let years = $date.getFullYear() - now.getFullYear();
|
|
12
|
+
if (now.getMonth() < $date.getMonth() || now.getMonth() === $date.getMonth() && now.getDate() < $date.getDate()) years--;
|
|
13
|
+
return years;
|
|
14
|
+
};
|
|
15
|
+
$Chronos.prototype.getRelativeMonth = function(time) {
|
|
16
|
+
const $date = this.toDate();
|
|
17
|
+
const now = toNewDate(this, time);
|
|
18
|
+
let months = ($date.getFullYear() - now.getFullYear()) * 12 + ($date.getMonth() - now.getMonth());
|
|
19
|
+
if (now.getDate() < $date.getDate()) months--;
|
|
20
|
+
return months;
|
|
21
|
+
};
|
|
22
|
+
$Chronos.prototype.getRelativeWeek = function(time) {
|
|
23
|
+
const relativeDays = this.getRelativeDay(time);
|
|
24
|
+
return Math.floor(relativeDays / 7);
|
|
25
|
+
};
|
|
26
|
+
$Chronos.prototype.getRelativeDay = function(time) {
|
|
27
|
+
const now = toNewDate(this, time);
|
|
28
|
+
now.setHours(0, 0, 0, 0);
|
|
29
|
+
const $date = new Date(this.toDate());
|
|
30
|
+
$date.setHours(0, 0, 0, 0);
|
|
31
|
+
const diffTime = $date.getTime() - now.getTime();
|
|
32
|
+
return Math.floor(diffTime / (1e3 * 60 * 60 * 24));
|
|
33
|
+
};
|
|
34
|
+
$Chronos.prototype.getRelativeHour = function(time) {
|
|
35
|
+
const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
36
|
+
return Math.floor(diff / (1e3 * 60 * 60));
|
|
37
|
+
};
|
|
38
|
+
$Chronos.prototype.getRelativeMinute = function(time) {
|
|
39
|
+
const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
40
|
+
return Math.floor(diff / (1e3 * 60));
|
|
41
|
+
};
|
|
42
|
+
$Chronos.prototype.getRelativeSecond = function(time) {
|
|
43
|
+
const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
44
|
+
return Math.floor(diff / 1e3);
|
|
45
|
+
};
|
|
46
|
+
$Chronos.prototype.getRelativeMilliSecond = function(time) {
|
|
47
|
+
return this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
48
|
+
};
|
|
49
|
+
$Chronos.prototype.compare = function(unit = "minute", time) {
|
|
50
|
+
switch (unit) {
|
|
51
|
+
case "year": return this.getRelativeYear(time);
|
|
52
|
+
case "month": return this.getRelativeMonth(time);
|
|
53
|
+
case "day": return this.getRelativeDay(time);
|
|
54
|
+
case "week": return this.getRelativeWeek(time);
|
|
55
|
+
case "hour": return this.getRelativeHour(time);
|
|
56
|
+
case "minute": return this.getRelativeMinute(time);
|
|
57
|
+
case "second": return this.getRelativeSecond(time);
|
|
58
|
+
case "millisecond": return this.getRelativeMilliSecond(time);
|
|
59
|
+
default: throw new RangeError(`Unsupported time unit: ${unit}`);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
$Chronos.prototype.isToday = function() {
|
|
63
|
+
return this.getRelativeDay() === 0;
|
|
64
|
+
};
|
|
65
|
+
$Chronos.prototype.isTomorrow = function() {
|
|
66
|
+
return this.getRelativeDay() === 1;
|
|
67
|
+
};
|
|
68
|
+
$Chronos.prototype.isYesterday = function() {
|
|
69
|
+
return this.getRelativeDay() === -1;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
exports.relativeTimePlugin = relativeTimePlugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, D as ChronosInput, Et as TimeUnit } from "../types-DPTQ_yLx.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/relativeTimePlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns the number of full years between the input date and now.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, D as ChronosInput, Et as TimeUnit } from "../types-B2fgrJ86.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/relativeTimePlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns the number of full years between the input date and now.
|
|
@@ -1 +1,73 @@
|
|
|
1
|
-
import{s as
|
|
1
|
+
import { s as INTERNALS } from "../basic-Dputob9z.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/relativeTimePlugin.ts
|
|
4
|
+
/** * Plugin to inject `relative time` related methods */
|
|
5
|
+
const relativeTimePlugin = ($Chronos) => {
|
|
6
|
+
const { toNewDate } = $Chronos[INTERNALS];
|
|
7
|
+
$Chronos.prototype.getRelativeYear = function(time) {
|
|
8
|
+
const $date = this.toDate();
|
|
9
|
+
const now = toNewDate(this, time);
|
|
10
|
+
let years = $date.getFullYear() - now.getFullYear();
|
|
11
|
+
if (now.getMonth() < $date.getMonth() || now.getMonth() === $date.getMonth() && now.getDate() < $date.getDate()) years--;
|
|
12
|
+
return years;
|
|
13
|
+
};
|
|
14
|
+
$Chronos.prototype.getRelativeMonth = function(time) {
|
|
15
|
+
const $date = this.toDate();
|
|
16
|
+
const now = toNewDate(this, time);
|
|
17
|
+
let months = ($date.getFullYear() - now.getFullYear()) * 12 + ($date.getMonth() - now.getMonth());
|
|
18
|
+
if (now.getDate() < $date.getDate()) months--;
|
|
19
|
+
return months;
|
|
20
|
+
};
|
|
21
|
+
$Chronos.prototype.getRelativeWeek = function(time) {
|
|
22
|
+
const relativeDays = this.getRelativeDay(time);
|
|
23
|
+
return Math.floor(relativeDays / 7);
|
|
24
|
+
};
|
|
25
|
+
$Chronos.prototype.getRelativeDay = function(time) {
|
|
26
|
+
const now = toNewDate(this, time);
|
|
27
|
+
now.setHours(0, 0, 0, 0);
|
|
28
|
+
const $date = new Date(this.toDate());
|
|
29
|
+
$date.setHours(0, 0, 0, 0);
|
|
30
|
+
const diffTime = $date.getTime() - now.getTime();
|
|
31
|
+
return Math.floor(diffTime / (1e3 * 60 * 60 * 24));
|
|
32
|
+
};
|
|
33
|
+
$Chronos.prototype.getRelativeHour = function(time) {
|
|
34
|
+
const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
35
|
+
return Math.floor(diff / (1e3 * 60 * 60));
|
|
36
|
+
};
|
|
37
|
+
$Chronos.prototype.getRelativeMinute = function(time) {
|
|
38
|
+
const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
39
|
+
return Math.floor(diff / (1e3 * 60));
|
|
40
|
+
};
|
|
41
|
+
$Chronos.prototype.getRelativeSecond = function(time) {
|
|
42
|
+
const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
43
|
+
return Math.floor(diff / 1e3);
|
|
44
|
+
};
|
|
45
|
+
$Chronos.prototype.getRelativeMilliSecond = function(time) {
|
|
46
|
+
return this.getTimeStamp() - toNewDate(this, time).getTime();
|
|
47
|
+
};
|
|
48
|
+
$Chronos.prototype.compare = function(unit = "minute", time) {
|
|
49
|
+
switch (unit) {
|
|
50
|
+
case "year": return this.getRelativeYear(time);
|
|
51
|
+
case "month": return this.getRelativeMonth(time);
|
|
52
|
+
case "day": return this.getRelativeDay(time);
|
|
53
|
+
case "week": return this.getRelativeWeek(time);
|
|
54
|
+
case "hour": return this.getRelativeHour(time);
|
|
55
|
+
case "minute": return this.getRelativeMinute(time);
|
|
56
|
+
case "second": return this.getRelativeSecond(time);
|
|
57
|
+
case "millisecond": return this.getRelativeMilliSecond(time);
|
|
58
|
+
default: throw new RangeError(`Unsupported time unit: ${unit}`);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
$Chronos.prototype.isToday = function() {
|
|
62
|
+
return this.getRelativeDay() === 0;
|
|
63
|
+
};
|
|
64
|
+
$Chronos.prototype.isTomorrow = function() {
|
|
65
|
+
return this.getRelativeDay() === 1;
|
|
66
|
+
};
|
|
67
|
+
$Chronos.prototype.isYesterday = function() {
|
|
68
|
+
return this.getRelativeDay() === -1;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { relativeTimePlugin };
|
|
@@ -1 +1,69 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_basic = require('../basic-DIp_pxR2.cjs');
|
|
3
|
+
const require_utilities = require('../utilities-CGL7F6R9.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/roundPlugin.ts
|
|
6
|
+
/** * Plugin to inject `round` method */
|
|
7
|
+
const roundPlugin = ($Chronos) => {
|
|
8
|
+
const { internalDate, withOrigin, offset } = $Chronos[require_basic.INTERNALS];
|
|
9
|
+
$Chronos.prototype.round = function(unit, nearest = 1) {
|
|
10
|
+
const date = new Date(internalDate(this));
|
|
11
|
+
switch (unit) {
|
|
12
|
+
case "millisecond": {
|
|
13
|
+
const rounded = require_utilities.roundToNearest(date.getMilliseconds(), nearest);
|
|
14
|
+
date.setMilliseconds(rounded);
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
case "second": {
|
|
18
|
+
const rounded = require_utilities.roundToNearest(date.getSeconds() + date.getMilliseconds() / 1e3, nearest);
|
|
19
|
+
date.setSeconds(rounded, 0);
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
case "minute": {
|
|
23
|
+
const rounded = require_utilities.roundToNearest(date.getMinutes() + date.getSeconds() / 60 + date.getMilliseconds() / 6e4, nearest);
|
|
24
|
+
date.setMinutes(rounded, 0, 0);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case "hour": {
|
|
28
|
+
const rounded = require_utilities.roundToNearest(date.getHours() + date.getMinutes() / 60 + date.getSeconds() / 3600 + date.getMilliseconds() / 36e5, nearest);
|
|
29
|
+
date.setHours(rounded, 0, 0, 0);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case "day": {
|
|
33
|
+
const rounded = require_utilities.roundToNearest(date.getDate() + (date.getHours() / 24 + date.getMinutes() / 1440 + date.getSeconds() / 86400 + date.getMilliseconds() / require_basic.MS_PER_DAY), nearest);
|
|
34
|
+
date.setDate(rounded);
|
|
35
|
+
date.setHours(0, 0, 0, 0);
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
case "week": {
|
|
39
|
+
const offsetToMonday = (date.getDay() + 6) % 7;
|
|
40
|
+
const startOfWeek = new Date(date);
|
|
41
|
+
startOfWeek.setDate(startOfWeek.getDate() - offsetToMonday);
|
|
42
|
+
startOfWeek.setHours(0, 0, 0, 0);
|
|
43
|
+
const endOfWeek = new Date(startOfWeek);
|
|
44
|
+
endOfWeek.setDate(endOfWeek.getDate() + 7);
|
|
45
|
+
const diffToStart = Math.abs(date.getTime() - startOfWeek.getTime());
|
|
46
|
+
return withOrigin(new $Chronos(Math.abs(endOfWeek.getTime() - date.getTime()) < diffToStart ? endOfWeek : startOfWeek), "round");
|
|
47
|
+
}
|
|
48
|
+
case "month": {
|
|
49
|
+
const roundedMonth = require_utilities.roundToNearest(date.getMonth() + date.getDate() / this.lastDateOfMonth, nearest);
|
|
50
|
+
date.setMonth(roundedMonth, 1);
|
|
51
|
+
date.setHours(0, 0, 0, 0);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case "year": {
|
|
55
|
+
const dayOfYear = Math.floor((date.getTime() - new Date(date.getFullYear(), 0, 1).getTime()) / require_basic.MS_PER_DAY);
|
|
56
|
+
const totalDays = new Date(date.getFullYear(), 1, 29).getDate() === 29 ? 366 : 365;
|
|
57
|
+
const roundedYear = require_utilities.roundToNearest(date.getFullYear() + dayOfYear / totalDays, nearest);
|
|
58
|
+
date.setFullYear(roundedYear, 0, 1);
|
|
59
|
+
date.setHours(0, 0, 0, 0);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
default: return this;
|
|
63
|
+
}
|
|
64
|
+
return withOrigin(new $Chronos(date), "round", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
exports.roundPlugin = roundPlugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, Et as TimeUnit } from "../types-DPTQ_yLx.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/roundPlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Rounds the current date-time to the nearest specified unit and interval.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, Et as TimeUnit } from "../types-B2fgrJ86.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/roundPlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Rounds the current date-time to the nearest specified unit and interval.
|
|
@@ -1 +1,68 @@
|
|
|
1
|
-
import{s as
|
|
1
|
+
import { s as INTERNALS, u as MS_PER_DAY } from "../basic-Dputob9z.mjs";
|
|
2
|
+
import { r as roundToNearest } from "../utilities-BU4MSYS7.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/roundPlugin.ts
|
|
5
|
+
/** * Plugin to inject `round` method */
|
|
6
|
+
const roundPlugin = ($Chronos) => {
|
|
7
|
+
const { internalDate, withOrigin, offset } = $Chronos[INTERNALS];
|
|
8
|
+
$Chronos.prototype.round = function(unit, nearest = 1) {
|
|
9
|
+
const date = new Date(internalDate(this));
|
|
10
|
+
switch (unit) {
|
|
11
|
+
case "millisecond": {
|
|
12
|
+
const rounded = roundToNearest(date.getMilliseconds(), nearest);
|
|
13
|
+
date.setMilliseconds(rounded);
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
case "second": {
|
|
17
|
+
const rounded = roundToNearest(date.getSeconds() + date.getMilliseconds() / 1e3, nearest);
|
|
18
|
+
date.setSeconds(rounded, 0);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case "minute": {
|
|
22
|
+
const rounded = roundToNearest(date.getMinutes() + date.getSeconds() / 60 + date.getMilliseconds() / 6e4, nearest);
|
|
23
|
+
date.setMinutes(rounded, 0, 0);
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
case "hour": {
|
|
27
|
+
const rounded = roundToNearest(date.getHours() + date.getMinutes() / 60 + date.getSeconds() / 3600 + date.getMilliseconds() / 36e5, nearest);
|
|
28
|
+
date.setHours(rounded, 0, 0, 0);
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
case "day": {
|
|
32
|
+
const rounded = roundToNearest(date.getDate() + (date.getHours() / 24 + date.getMinutes() / 1440 + date.getSeconds() / 86400 + date.getMilliseconds() / MS_PER_DAY), nearest);
|
|
33
|
+
date.setDate(rounded);
|
|
34
|
+
date.setHours(0, 0, 0, 0);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case "week": {
|
|
38
|
+
const offsetToMonday = (date.getDay() + 6) % 7;
|
|
39
|
+
const startOfWeek = new Date(date);
|
|
40
|
+
startOfWeek.setDate(startOfWeek.getDate() - offsetToMonday);
|
|
41
|
+
startOfWeek.setHours(0, 0, 0, 0);
|
|
42
|
+
const endOfWeek = new Date(startOfWeek);
|
|
43
|
+
endOfWeek.setDate(endOfWeek.getDate() + 7);
|
|
44
|
+
const diffToStart = Math.abs(date.getTime() - startOfWeek.getTime());
|
|
45
|
+
return withOrigin(new $Chronos(Math.abs(endOfWeek.getTime() - date.getTime()) < diffToStart ? endOfWeek : startOfWeek), "round");
|
|
46
|
+
}
|
|
47
|
+
case "month": {
|
|
48
|
+
const roundedMonth = roundToNearest(date.getMonth() + date.getDate() / this.lastDateOfMonth, nearest);
|
|
49
|
+
date.setMonth(roundedMonth, 1);
|
|
50
|
+
date.setHours(0, 0, 0, 0);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case "year": {
|
|
54
|
+
const dayOfYear = Math.floor((date.getTime() - new Date(date.getFullYear(), 0, 1).getTime()) / MS_PER_DAY);
|
|
55
|
+
const totalDays = new Date(date.getFullYear(), 1, 29).getDate() === 29 ? 366 : 365;
|
|
56
|
+
const roundedYear = roundToNearest(date.getFullYear() + dayOfYear / totalDays, nearest);
|
|
57
|
+
date.setFullYear(roundedYear, 0, 1);
|
|
58
|
+
date.setHours(0, 0, 0, 0);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
default: return this;
|
|
62
|
+
}
|
|
63
|
+
return withOrigin(new $Chronos(date), "round", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { roundPlugin };
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_seasons = require('../seasons-CcZicoe1.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/seasonPlugin.ts
|
|
5
|
+
/** * Plugin to inject `season`/`getSeasonName` method */
|
|
6
|
+
const seasonPlugin = ($Chronos) => {
|
|
7
|
+
$Chronos.prototype.season = function(options) {
|
|
8
|
+
const { preset = "default" } = options ?? {};
|
|
9
|
+
const seasonSet = options?.seasons ?? require_seasons.SEASON_PRESETS[preset];
|
|
10
|
+
const dateStr = this.format("MM-DD");
|
|
11
|
+
for (const { name, boundary } of seasonSet) if ("startDate" in boundary && "endDate" in boundary) {
|
|
12
|
+
const start = boundary.startDate;
|
|
13
|
+
const end = boundary.endDate;
|
|
14
|
+
if (start <= end) {
|
|
15
|
+
if (dateStr >= start && dateStr <= end) return name;
|
|
16
|
+
} else if (dateStr >= start || dateStr <= end) return name;
|
|
17
|
+
} else if ("startMonth" in boundary && "endMonth" in boundary) {
|
|
18
|
+
const { startMonth, endMonth } = boundary;
|
|
19
|
+
if (startMonth <= endMonth) {
|
|
20
|
+
if (this.month >= startMonth && this.month <= endMonth) return name;
|
|
21
|
+
} else if (this.month >= startMonth || this.month <= endMonth) return name;
|
|
22
|
+
}
|
|
23
|
+
return "Unknown";
|
|
24
|
+
};
|
|
25
|
+
$Chronos.prototype.getSeasonName = function(options) {
|
|
26
|
+
return this.season(options);
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.seasonPlugin = seasonPlugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, m as SeasonOptions } from "../types-DPTQ_yLx.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/seasonPlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns the current season name based on optional season rules or presets.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, m as SeasonOptions } from "../types-B2fgrJ86.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/seasonPlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Returns the current season name based on optional season rules or presets.
|
|
@@ -1 +1,30 @@
|
|
|
1
|
-
import{u as
|
|
1
|
+
import { u as SEASON_PRESETS } from "../seasons-CHnjrIKK.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/seasonPlugin.ts
|
|
4
|
+
/** * Plugin to inject `season`/`getSeasonName` method */
|
|
5
|
+
const seasonPlugin = ($Chronos) => {
|
|
6
|
+
$Chronos.prototype.season = function(options) {
|
|
7
|
+
const { preset = "default" } = options ?? {};
|
|
8
|
+
const seasonSet = options?.seasons ?? SEASON_PRESETS[preset];
|
|
9
|
+
const dateStr = this.format("MM-DD");
|
|
10
|
+
for (const { name, boundary } of seasonSet) if ("startDate" in boundary && "endDate" in boundary) {
|
|
11
|
+
const start = boundary.startDate;
|
|
12
|
+
const end = boundary.endDate;
|
|
13
|
+
if (start <= end) {
|
|
14
|
+
if (dateStr >= start && dateStr <= end) return name;
|
|
15
|
+
} else if (dateStr >= start || dateStr <= end) return name;
|
|
16
|
+
} else if ("startMonth" in boundary && "endMonth" in boundary) {
|
|
17
|
+
const { startMonth, endMonth } = boundary;
|
|
18
|
+
if (startMonth <= endMonth) {
|
|
19
|
+
if (this.month >= startMonth && this.month <= endMonth) return name;
|
|
20
|
+
} else if (this.month >= startMonth || this.month <= endMonth) return name;
|
|
21
|
+
}
|
|
22
|
+
return "Unknown";
|
|
23
|
+
};
|
|
24
|
+
$Chronos.prototype.getSeasonName = function(options) {
|
|
25
|
+
return this.season(options);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { seasonPlugin };
|
|
@@ -1 +1,139 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_basic = require('../basic-DIp_pxR2.cjs');
|
|
3
|
+
const require_timezone = require('../timezone-DYVJJYKz.cjs');
|
|
4
|
+
const require_guards = require('../guards.cjs');
|
|
5
|
+
const require_helpers = require('../helpers-M_SfAbAv.cjs');
|
|
6
|
+
const require_utilities = require('../utilities-bXwTPJaD.cjs');
|
|
7
|
+
|
|
8
|
+
//#region src/plugins/timeZonePlugin.ts
|
|
9
|
+
/** * Plugin to inject `timeZone` related methods */
|
|
10
|
+
const timeZonePlugin = ($Chronos) => {
|
|
11
|
+
const { internalDate: $Date, withOrigin, offset } = $Chronos[require_basic.INTERNALS];
|
|
12
|
+
/** Check if a time zone factor represents GMT */
|
|
13
|
+
const _isGMT = (factor) => {
|
|
14
|
+
return factor === "UTC+00:00" || factor === "UTC-00:00";
|
|
15
|
+
};
|
|
16
|
+
/** Check if a string is the key of `TIME_ZONE_LABELS` constant */
|
|
17
|
+
const _isLabelKey = (offset) => {
|
|
18
|
+
return offset ? offset in require_timezone.TIME_ZONE_LABELS : false;
|
|
19
|
+
};
|
|
20
|
+
/** Check if a string is time zone abbreviation */
|
|
21
|
+
const _isValidTzAbbr = (tz) => {
|
|
22
|
+
return tz in require_timezone.TIME_ZONES;
|
|
23
|
+
};
|
|
24
|
+
/** Resolve time zone name from `TIME_ZONE_LABELS` constant using UTC offset or get undefined */
|
|
25
|
+
const _resolveTzName = (offset) => {
|
|
26
|
+
if (_isLabelKey(offset)) return require_timezone.TIME_ZONE_LABELS[offset];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* * Retrieves comprehensive time zone details using the {@link Intl.supportedValuesOf} API.
|
|
30
|
+
* @param tzId Time zone identifier. Defaults to the system timezone.
|
|
31
|
+
* @param date Date for which to resolve the information.
|
|
32
|
+
* @returns Object containing time zone identifier, name, and offset.
|
|
33
|
+
*/
|
|
34
|
+
const _getTimeZoneDetails = (tzId, date) => {
|
|
35
|
+
const TZ_NAME_TYPES = ["long", "longOffset"];
|
|
36
|
+
const obj = { tzId };
|
|
37
|
+
for (const type of TZ_NAME_TYPES) {
|
|
38
|
+
const key = type === "long" ? "tzName" : "offset";
|
|
39
|
+
try {
|
|
40
|
+
const partValue = require_helpers._resolveNativeTzName(tzId, type, date);
|
|
41
|
+
obj[key] = type === "longOffset" ? require_helpers._gmtToUtcOffset(partValue) : partValue;
|
|
42
|
+
} catch {
|
|
43
|
+
obj[key] = void 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return obj;
|
|
47
|
+
};
|
|
48
|
+
/** Cache to store time zone id (from {@link Intl.supportedValuesOf}) against UTC offset */
|
|
49
|
+
const TZ_ID_MAP = new Map(require_timezone.NATIVE_TZ_IDS.reduce((tzIds, id) => {
|
|
50
|
+
const { offset } = _getTimeZoneDetails(id);
|
|
51
|
+
if (offset) {
|
|
52
|
+
const arr = tzIds.get(offset) ?? [];
|
|
53
|
+
arr.push(id);
|
|
54
|
+
tzIds.set(offset, arr);
|
|
55
|
+
}
|
|
56
|
+
return tzIds;
|
|
57
|
+
}, /* @__PURE__ */ new Map()));
|
|
58
|
+
/** Cache to store time zone name and abbreviation against UTC offset from {@link TIME_ZONES} */
|
|
59
|
+
const TZ_NAME_ABBR_MAP = new Map(Object.entries(require_timezone.TIME_ZONES).map(([tzAbbr, { offset, tzName }]) => [offset, {
|
|
60
|
+
tzAbbr,
|
|
61
|
+
tzName
|
|
62
|
+
}]));
|
|
63
|
+
/** Get time zone identifier from {@link TZ_ID_MAP} using UTC offset */
|
|
64
|
+
const _getTimeZoneId = (utc) => {
|
|
65
|
+
const tzIds = TZ_ID_MAP.get(utc);
|
|
66
|
+
if (!tzIds || tzIds?.length === 0) return void 0;
|
|
67
|
+
if (tzIds?.length === 1) return tzIds[0];
|
|
68
|
+
return tzIds;
|
|
69
|
+
};
|
|
70
|
+
/** Get time zone name from `Intl.supportedValuesOf('timeZone')`, `TIME_ZONE_LABELS` or `TIME_ZONES` constants using UTC offset, time zone identifier or time zone abbreviation */
|
|
71
|
+
const _getTimeZoneName = (zone, date) => {
|
|
72
|
+
if (_isGMT(zone)) return "Greenwich Mean Time";
|
|
73
|
+
if (require_guards.isValidUTCOffset(zone)) {
|
|
74
|
+
const tzName = _resolveTzName(zone);
|
|
75
|
+
if (!tzName && TZ_NAME_ABBR_MAP.has(zone)) return TZ_NAME_ABBR_MAP.get(zone)?.tzName;
|
|
76
|
+
return tzName;
|
|
77
|
+
} else if (_isValidTzAbbr(zone)) return require_timezone.TIME_ZONES[zone].tzName;
|
|
78
|
+
else {
|
|
79
|
+
const { offset, tzName } = _getTimeZoneDetails(zone, date);
|
|
80
|
+
return tzName || _resolveTzName(offset);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
$Chronos.prototype.timeZone = function(zone) {
|
|
84
|
+
let offset;
|
|
85
|
+
let tzId;
|
|
86
|
+
if (require_guards.isValidUTCOffset(zone)) {
|
|
87
|
+
offset = zone;
|
|
88
|
+
tzId = _getTimeZoneId(offset) || offset;
|
|
89
|
+
} else if (_isValidTzAbbr(zone)) {
|
|
90
|
+
offset = require_timezone.TIME_ZONES[zone].offset;
|
|
91
|
+
tzId = _getTimeZoneId(offset) || offset;
|
|
92
|
+
} else {
|
|
93
|
+
offset = _getTimeZoneDetails(zone, $Date(this)).offset || require_timezone.TIME_ZONES["UTC"].offset;
|
|
94
|
+
tzId = zone;
|
|
95
|
+
}
|
|
96
|
+
const $zone = zone || offset;
|
|
97
|
+
const tzName = _getTimeZoneName($zone, $Date(this)) ?? offset;
|
|
98
|
+
const relativeOffset = require_utilities.extractMinutesFromUTC(offset) - this.getTimeZoneOffsetMinutes();
|
|
99
|
+
return withOrigin(new $Chronos(new Date($Date(this).getTime() + relativeOffset * 60 * 1e3)), `timeZone`, offset, tzName, tzId, $zone);
|
|
100
|
+
};
|
|
101
|
+
$Chronos.prototype.getTimeZoneName = function(utc) {
|
|
102
|
+
const UTC = utc || offset(this);
|
|
103
|
+
return _getTimeZoneName(utc || this?.$tzTracker || offset(this), $Date(this)) ?? UTC;
|
|
104
|
+
};
|
|
105
|
+
/** Cache to store abbreviated time zone names */
|
|
106
|
+
const TZ_ABBR_CACHE = /* @__PURE__ */ new Map();
|
|
107
|
+
/** Abbreviate full time zone name */
|
|
108
|
+
const _abbreviate = (name) => {
|
|
109
|
+
return name.split(/\s+/).map((w) => w[0]).join("").replace(/\W/g, "");
|
|
110
|
+
};
|
|
111
|
+
$Chronos.prototype.getTimeZoneNameShort = function(utc) {
|
|
112
|
+
const tracker = this?.$tzTracker;
|
|
113
|
+
const UTC = utc || offset(this);
|
|
114
|
+
const tzMapKey = utc || tracker || offset(this);
|
|
115
|
+
if (_isGMT(tzMapKey)) return "GMT";
|
|
116
|
+
if (!utc && tracker && _isValidTzAbbr(tracker)) return tracker;
|
|
117
|
+
if (require_guards.isValidUTCOffset(tzMapKey)) {
|
|
118
|
+
if (TZ_ABBR_CACHE.has(tzMapKey)) return TZ_ABBR_CACHE.get(tzMapKey);
|
|
119
|
+
if (TZ_NAME_ABBR_MAP.has(tzMapKey)) return TZ_NAME_ABBR_MAP.get(tzMapKey)?.tzAbbr;
|
|
120
|
+
const tzName = _resolveTzName(tzMapKey);
|
|
121
|
+
if (tzName) {
|
|
122
|
+
const tzAbbr = _abbreviate(tzName);
|
|
123
|
+
TZ_ABBR_CACHE.set(tzMapKey, tzAbbr);
|
|
124
|
+
return tzAbbr;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const zone = _getTimeZoneName(tzMapKey, $Date(this)) ?? UTC;
|
|
128
|
+
if (TZ_ABBR_CACHE.has(`name-${zone}`)) return TZ_ABBR_CACHE.get(zone);
|
|
129
|
+
const customAbbr = require_guards.isValidUTCOffset(zone) ? zone : _abbreviate(zone);
|
|
130
|
+
TZ_ABBR_CACHE.set(`name-${zone}`, customAbbr);
|
|
131
|
+
return customAbbr;
|
|
132
|
+
};
|
|
133
|
+
$Chronos.prototype.getTimeZoneNameAbbr = function(utc) {
|
|
134
|
+
return this.getTimeZoneNameShort(utc);
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
exports.timeZonePlugin = timeZonePlugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as $Chronos, En as LooseLiteral, Nt as TimeZoneIdentifier, Pt as TimeZoneName, Rt as UTCOffset, kt as TimeZone } from "../types-DPTQ_yLx.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/timeZonePlugin.d.ts
|
|
4
|
-
declare module '
|
|
4
|
+
declare module 'chronos-date' {
|
|
5
5
|
interface Chronos {
|
|
6
6
|
/**
|
|
7
7
|
* @instance Creates a new instance of `Chronos` for the specified time zone identifier.
|