nhb-toolbox 4.21.4 → 4.21.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +8 -8
- package/dist/cjs/date/Chronos.js +2 -75
- package/dist/cjs/date/plugins/roundPlugin.js +84 -0
- package/dist/dts/date/Chronos.d.ts +36 -54
- package/dist/dts/date/plugins/roundPlugin.d.ts +28 -0
- package/dist/dts/date/types.d.ts +5 -3
- package/dist/esm/date/Chronos.js +3 -76
- package/dist/esm/date/plugins/roundPlugin.js +80 -0
- package/package.json +9 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,11 @@ All notable changes to the package will be documented here.
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [4.21.10] - 2025-10-13
|
|
10
|
+
|
|
11
|
+
- **Moved** `round` method to `Chronos` *plugin system*, usable via `roundPlugin`.
|
|
12
|
+
- **Updated** *tsdoc* for some `Chronos` methods with *proper references.*
|
|
13
|
+
|
|
9
14
|
## [4.21.4] - 2025-10-13
|
|
10
15
|
|
|
11
16
|
- **Added** new type `$UTCOffset` and applied in corresponding `Chronos` methods.
|
package/README.md
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<a href="https://www.npmjs.com/package/nhb-toolbox" aria-label="NPM Downloads">
|
|
8
8
|
<img src="https://img.shields.io/npm/dm/nhb-toolbox.svg?label=DOWNLOADS&style=flat&color=red&logo=npm" alt="Downloads" />
|
|
9
9
|
</a>
|
|
10
|
-
<a href="https://www.npmjs.com/package/nhb-toolbox" aria-label="
|
|
11
|
-
<img src="https://img.shields.io/npm/v/nhb-toolbox.svg?label=
|
|
10
|
+
<a href="https://www.npmjs.com/package/nhb-toolbox" aria-label="Latest Version">
|
|
11
|
+
<img src="https://img.shields.io/npm/v/nhb-toolbox.svg?label=NPM&style=flat&color=teal&logo=npm" alt="Latest Version" />
|
|
12
12
|
</a>
|
|
13
13
|
<a href="https://bundlephobia.com/result?p=nhb-toolbox" aria-label="Bundle Size">
|
|
14
14
|
<img src="https://img.shields.io/bundlephobia/minzip/nhb-toolbox?style=flat&color=purple&label=SIZE&logo=nodedotjs" alt="Bundle Size" />
|
|
@@ -88,15 +88,15 @@ yarn add nhb-toolbox
|
|
|
88
88
|
|
|
89
89
|
---
|
|
90
90
|
|
|
91
|
+
### Installing from GitHub Packages
|
|
92
|
+
|
|
93
|
+
GitHub Packages requires authentication and scoped package names.
|
|
94
|
+
|
|
91
95
|
<details>
|
|
92
96
|
|
|
93
97
|
<summary>
|
|
94
|
-
|
|
95
|
-
### Installing from GitHub Packages
|
|
96
|
-
|
|
98
|
+
<strong>Details</strong>
|
|
97
99
|
</summary>
|
|
98
|
-
|
|
99
|
-
GitHub Packages requires authentication and scoped package names.
|
|
100
100
|
|
|
101
101
|
#### Step 1: Authenticate with GitHub Packages
|
|
102
102
|
|
|
@@ -172,7 +172,7 @@ Example `.npmrc` snippet:
|
|
|
172
172
|
|
|
173
173
|
| Registry | Package Name | Registry URL | Requires Auth? |
|
|
174
174
|
| --------------- | ------------------------- | -------------------------------------------------------- | ------------------------------ |
|
|
175
|
-
| NPM Registry
|
|
175
|
+
| NPM Registry | `nhb-toolbox` | [https://registry.npmjs.org](https://registry.npmjs.org) | No |
|
|
176
176
|
| GitHub Packages | `@nazmul-nhb/nhb-toolbox` | [https://npm.pkg.github.com](https://npm.pkg.github.com) | Yes (PAT with `read:packages`) |
|
|
177
177
|
|
|
178
178
|
---
|
package/dist/cjs/date/Chronos.js
CHANGED
|
@@ -432,6 +432,8 @@ class Chronos {
|
|
|
432
432
|
return t > s && t <= e;
|
|
433
433
|
case '()':
|
|
434
434
|
return t > s && t < e;
|
|
435
|
+
default:
|
|
436
|
+
return false;
|
|
435
437
|
}
|
|
436
438
|
}
|
|
437
439
|
isDST() {
|
|
@@ -736,81 +738,6 @@ class Chronos {
|
|
|
736
738
|
const localTime = new Date(this.#date.getTime() - relativeOffset * 60 * 1000);
|
|
737
739
|
return new _a(localTime).#withOrigin('toLocal');
|
|
738
740
|
}
|
|
739
|
-
round(unit, nearest = 1) {
|
|
740
|
-
const date = new Date(this.#date);
|
|
741
|
-
switch (unit) {
|
|
742
|
-
case 'millisecond': {
|
|
743
|
-
const rounded = (0, utilities_1.roundToNearest)(date.getMilliseconds(), nearest);
|
|
744
|
-
date.setMilliseconds(rounded);
|
|
745
|
-
break;
|
|
746
|
-
}
|
|
747
|
-
case 'second': {
|
|
748
|
-
const fullSecond = date.getSeconds() + date.getMilliseconds() / 1000;
|
|
749
|
-
const rounded = (0, utilities_1.roundToNearest)(fullSecond, nearest);
|
|
750
|
-
date.setSeconds(rounded, 0);
|
|
751
|
-
break;
|
|
752
|
-
}
|
|
753
|
-
case 'minute': {
|
|
754
|
-
const fullMinute = date.getMinutes() + date.getSeconds() / 60 + date.getMilliseconds() / 60000;
|
|
755
|
-
const rounded = (0, utilities_1.roundToNearest)(fullMinute, nearest);
|
|
756
|
-
date.setMinutes(rounded, 0, 0);
|
|
757
|
-
break;
|
|
758
|
-
}
|
|
759
|
-
case 'hour': {
|
|
760
|
-
const fullHour = date.getHours() +
|
|
761
|
-
date.getMinutes() / 60 +
|
|
762
|
-
date.getSeconds() / 3600 +
|
|
763
|
-
date.getMilliseconds() / 3600000;
|
|
764
|
-
const rounded = (0, utilities_1.roundToNearest)(fullHour, nearest);
|
|
765
|
-
date.setHours(rounded, 0, 0, 0);
|
|
766
|
-
break;
|
|
767
|
-
}
|
|
768
|
-
case 'day': {
|
|
769
|
-
const fullDay = date.getDate() +
|
|
770
|
-
(date.getHours() / 24 +
|
|
771
|
-
date.getMinutes() / 1440 +
|
|
772
|
-
date.getSeconds() / 86400 +
|
|
773
|
-
date.getMilliseconds() / 86400000);
|
|
774
|
-
const rounded = (0, utilities_1.roundToNearest)(fullDay, nearest);
|
|
775
|
-
date.setDate(rounded);
|
|
776
|
-
date.setHours(0, 0, 0, 0);
|
|
777
|
-
break;
|
|
778
|
-
}
|
|
779
|
-
case 'week': {
|
|
780
|
-
const weekday = this.#date.getDay();
|
|
781
|
-
const offsetToMonday = (weekday + 6) % 7;
|
|
782
|
-
const startOfWeek = new Date(this.#date);
|
|
783
|
-
startOfWeek.setDate(startOfWeek.getDate() - offsetToMonday);
|
|
784
|
-
startOfWeek.setHours(0, 0, 0, 0);
|
|
785
|
-
const endOfWeek = new Date(startOfWeek);
|
|
786
|
-
endOfWeek.setDate(endOfWeek.getDate() + 7);
|
|
787
|
-
const diffToStart = Math.abs(this.#date.getTime() - startOfWeek.getTime());
|
|
788
|
-
const diffToEnd = Math.abs(endOfWeek.getTime() - this.#date.getTime());
|
|
789
|
-
const rounded = diffToEnd < diffToStart ? endOfWeek : startOfWeek;
|
|
790
|
-
return new _a(rounded).#withOrigin('round');
|
|
791
|
-
}
|
|
792
|
-
case 'month': {
|
|
793
|
-
const fullMonth = date.getMonth() + date.getDate() / this.lastDateOfMonth;
|
|
794
|
-
const roundedMonth = (0, utilities_1.roundToNearest)(fullMonth, nearest);
|
|
795
|
-
date.setMonth(roundedMonth, 1);
|
|
796
|
-
date.setHours(0, 0, 0, 0);
|
|
797
|
-
break;
|
|
798
|
-
}
|
|
799
|
-
case 'year': {
|
|
800
|
-
const dayOfYear = Math.floor((date.getTime() - new Date(date.getFullYear(), 0, 1).getTime()) / 86400000);
|
|
801
|
-
const isLeap = new Date(date.getFullYear(), 1, 29).getDate() === 29;
|
|
802
|
-
const totalDays = isLeap ? 366 : 365;
|
|
803
|
-
const fullYear = date.getFullYear() + dayOfYear / totalDays;
|
|
804
|
-
const roundedYear = (0, utilities_1.roundToNearest)(fullYear, nearest);
|
|
805
|
-
date.setFullYear(roundedYear, 0, 1);
|
|
806
|
-
date.setHours(0, 0, 0, 0);
|
|
807
|
-
break;
|
|
808
|
-
}
|
|
809
|
-
default:
|
|
810
|
-
return this;
|
|
811
|
-
}
|
|
812
|
-
return new _a(date).#withOrigin('round');
|
|
813
|
-
}
|
|
814
741
|
duration(toTime, absolute = true) {
|
|
815
742
|
const now = this.#date;
|
|
816
743
|
const target = this.#toNewDate(toTime);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.roundPlugin = void 0;
|
|
4
|
+
const utilities_1 = require("../../number/utilities");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const roundPlugin = (ChronosClass) => {
|
|
7
|
+
const internal = ChronosClass[constants_1.INTERNALS];
|
|
8
|
+
ChronosClass.prototype.round = function (unit, nearest = 1) {
|
|
9
|
+
const date = internal.internalDate(this);
|
|
10
|
+
switch (unit) {
|
|
11
|
+
case 'millisecond': {
|
|
12
|
+
const rounded = (0, utilities_1.roundToNearest)(date.getMilliseconds(), nearest);
|
|
13
|
+
date.setMilliseconds(rounded);
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
case 'second': {
|
|
17
|
+
const fullSecond = date.getSeconds() + date.getMilliseconds() / 1000;
|
|
18
|
+
const rounded = (0, utilities_1.roundToNearest)(fullSecond, nearest);
|
|
19
|
+
date.setSeconds(rounded, 0);
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
case 'minute': {
|
|
23
|
+
const fullMinute = date.getMinutes() + date.getSeconds() / 60 + date.getMilliseconds() / 60000;
|
|
24
|
+
const rounded = (0, utilities_1.roundToNearest)(fullMinute, nearest);
|
|
25
|
+
date.setMinutes(rounded, 0, 0);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
case 'hour': {
|
|
29
|
+
const fullHour = date.getHours() +
|
|
30
|
+
date.getMinutes() / 60 +
|
|
31
|
+
date.getSeconds() / 3600 +
|
|
32
|
+
date.getMilliseconds() / 3600000;
|
|
33
|
+
const rounded = (0, utilities_1.roundToNearest)(fullHour, nearest);
|
|
34
|
+
date.setHours(rounded, 0, 0, 0);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case 'day': {
|
|
38
|
+
const fullDay = date.getDate() +
|
|
39
|
+
(date.getHours() / 24 +
|
|
40
|
+
date.getMinutes() / 1440 +
|
|
41
|
+
date.getSeconds() / 86400 +
|
|
42
|
+
date.getMilliseconds() / 86400000);
|
|
43
|
+
const rounded = (0, utilities_1.roundToNearest)(fullDay, nearest);
|
|
44
|
+
date.setDate(rounded);
|
|
45
|
+
date.setHours(0, 0, 0, 0);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case 'week': {
|
|
49
|
+
const weekday = date.getDay();
|
|
50
|
+
const offsetToMonday = (weekday + 6) % 7;
|
|
51
|
+
const startOfWeek = new Date(date);
|
|
52
|
+
startOfWeek.setDate(startOfWeek.getDate() - offsetToMonday);
|
|
53
|
+
startOfWeek.setHours(0, 0, 0, 0);
|
|
54
|
+
const endOfWeek = new Date(startOfWeek);
|
|
55
|
+
endOfWeek.setDate(endOfWeek.getDate() + 7);
|
|
56
|
+
const diffToStart = Math.abs(date.getTime() - startOfWeek.getTime());
|
|
57
|
+
const diffToEnd = Math.abs(endOfWeek.getTime() - date.getTime());
|
|
58
|
+
const rounded = diffToEnd < diffToStart ? endOfWeek : startOfWeek;
|
|
59
|
+
return internal.withOrigin(new ChronosClass(rounded), 'round');
|
|
60
|
+
}
|
|
61
|
+
case 'month': {
|
|
62
|
+
const fullMonth = date.getMonth() + date.getDate() / this.lastDateOfMonth;
|
|
63
|
+
const roundedMonth = (0, utilities_1.roundToNearest)(fullMonth, nearest);
|
|
64
|
+
date.setMonth(roundedMonth, 1);
|
|
65
|
+
date.setHours(0, 0, 0, 0);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case 'year': {
|
|
69
|
+
const dayOfYear = Math.floor((date.getTime() - new Date(date.getFullYear(), 0, 1).getTime()) / 86400000);
|
|
70
|
+
const isLeap = new Date(date.getFullYear(), 1, 29).getDate() === 29;
|
|
71
|
+
const totalDays = isLeap ? 366 : 365;
|
|
72
|
+
const fullYear = date.getFullYear() + dayOfYear / totalDays;
|
|
73
|
+
const roundedYear = (0, utilities_1.roundToNearest)(fullYear, nearest);
|
|
74
|
+
date.setFullYear(roundedYear, 0, 1);
|
|
75
|
+
date.setHours(0, 0, 0, 0);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
default:
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
return internal.withOrigin(new ChronosClass(date), 'round');
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
exports.roundPlugin = roundPlugin;
|
|
@@ -12,7 +12,7 @@ import type { $UTCOffset, ChronosInput, ChronosInternals, ChronosMethods, Chrono
|
|
|
12
12
|
* - If a string is provided, it should be in a format that can be parsed by the Date constructor.
|
|
13
13
|
* - If a number is provided, it should be a timestamp (milliseconds since the Unix epoch).
|
|
14
14
|
* - If a Date object is provided, it will be used as is.
|
|
15
|
-
* - If a Chronos object is provided, it will be converted to a Date object.
|
|
15
|
+
* - If a `Chronos` object is provided, it will be converted to a Date object.
|
|
16
16
|
*
|
|
17
17
|
* **It also accepts number values as following:**
|
|
18
18
|
* - **`year, month, date, hours, minutes, seconds, milliseconds`**: Individual components of a date-time to construct a `Chronos` instance.
|
|
@@ -31,7 +31,7 @@ export declare class Chronos {
|
|
|
31
31
|
/** Use `readonly and/or private` methods outside `Chronos`. Purpose: Plugin creation. */
|
|
32
32
|
protected static [INTERNALS]: ChronosInternals;
|
|
33
33
|
/**
|
|
34
|
-
* * Chronos date/time in Native JS `Date` format.
|
|
34
|
+
* * `Chronos` date/time in Native JS `Date` format.
|
|
35
35
|
*
|
|
36
36
|
* - **NOTE**: It is **HIGHLY** advised *not to rely* on this public property to access native JS `Date`. It's not reliable when timezone and/or UTC related operations are performed. If you really need to use native `Date`, use `toDate` method. THis property is purely for developer convenience and sugar.
|
|
37
37
|
*/
|
|
@@ -94,12 +94,12 @@ export declare class Chronos {
|
|
|
94
94
|
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
95
95
|
*
|
|
96
96
|
* @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99, year is assumed to be 1900 + year.
|
|
97
|
-
* @param month The month as a number between 1 and 12 (January to December).
|
|
98
|
-
* @param date The date as a number between 1 and 31.
|
|
99
|
-
* @param hours Must be supplied if minutes is supplied. A number from 0 to 23 (midnight to 11pm) that specifies the hour.
|
|
100
|
-
* @param minutes Must be supplied if seconds is supplied. A number from 0 to 59 that specifies the minutes.
|
|
101
|
-
* @param seconds Must be supplied if milliseconds is supplied. A number from 0 to 59 that specifies the seconds.
|
|
102
|
-
* @param ms A number from 0 to 999 that specifies the milliseconds.
|
|
97
|
+
* @param month The month as a `number` between 1 and 12 (January to December).
|
|
98
|
+
* @param date The date as a `number` between 1 and 31.
|
|
99
|
+
* @param hours Must be supplied if minutes is supplied. A `number` from 0 to 23 (midnight to 11pm) that specifies the hour.
|
|
100
|
+
* @param minutes Must be supplied if seconds is supplied. A `number` from 0 to 59 that specifies the minutes.
|
|
101
|
+
* @param seconds Must be supplied if milliseconds is supplied. A `number` from 0 to 59 that specifies the seconds.
|
|
102
|
+
* @param ms A `number` from 0 to 999 that specifies the milliseconds.
|
|
103
103
|
*
|
|
104
104
|
* @returns Instance of `Chronos` with all methods and properties.
|
|
105
105
|
*/
|
|
@@ -111,10 +111,10 @@ export declare class Chronos {
|
|
|
111
111
|
* and convert it to the **equivalent local time** using the current environment's UTC offset.*
|
|
112
112
|
*
|
|
113
113
|
* @param value - A date value (`number`, `string`, `Date`, or `Chronos` object).
|
|
114
|
-
* - If a string is provided, it should be in a format that can be parsed by the `Date` constructor.
|
|
115
|
-
* - If a number is provided, it should be a timestamp (milliseconds since the Unix epoch).
|
|
116
|
-
* - If a Date object is provided, it will be used as is.
|
|
117
|
-
* - If a Chronos object is provided, it will be used directly.
|
|
114
|
+
* - If a `string` is provided, it should be in a format that can be parsed by the `Date` constructor.
|
|
115
|
+
* - If a `number` is provided, it should be a timestamp (milliseconds since the Unix epoch).
|
|
116
|
+
* - If a `Date` object is provided, it will be used as is.
|
|
117
|
+
* - If a `Chronos` object is provided, it will be used directly.
|
|
118
118
|
*
|
|
119
119
|
* @returns Instance of `Chronos` with all methods and properties.
|
|
120
120
|
*/
|
|
@@ -164,7 +164,7 @@ export declare class Chronos {
|
|
|
164
164
|
toJSON(): string;
|
|
165
165
|
/** @instance Enables arithmetic and comparison operations (e.g., +new Chronos()). */
|
|
166
166
|
valueOf(): number;
|
|
167
|
-
/** @instance Clones and returns a new Chronos instance with the same date. */
|
|
167
|
+
/** @instance Clones and returns a new `Chronos` instance with the same date. */
|
|
168
168
|
clone(): Chronos;
|
|
169
169
|
/** @instance Gets the native `Date` instance (read-only). */
|
|
170
170
|
toDate(): Date;
|
|
@@ -206,7 +206,7 @@ export declare class Chronos {
|
|
|
206
206
|
/**
|
|
207
207
|
* @instance Formats the date into a predefined strict string format using local time or UTC.
|
|
208
208
|
*
|
|
209
|
-
* @remarks Offers over 21,000 predefined formats with full IntelliSense support.
|
|
209
|
+
* @remarks Offers `over 21,000` predefined formats with full IntelliSense support.
|
|
210
210
|
*
|
|
211
211
|
* @param format - The desired format string. Defaults to `'dd, mmm DD, YYYY HH:mm:ss'`
|
|
212
212
|
* (e.g., `'Sun, Apr 06, 2025 16:11:55'`).
|
|
@@ -346,30 +346,30 @@ export declare class Chronos {
|
|
|
346
346
|
isFirstDayOfMonth(): boolean;
|
|
347
347
|
/** @instance Checks if current day is the last day of the current month. */
|
|
348
348
|
isLastDayOfMonth(): boolean;
|
|
349
|
-
/** @instance Returns a new Chronos instance set to the first day of the current month. */
|
|
349
|
+
/** @instance Returns a new `Chronos` instance set to the first day of the current month. */
|
|
350
350
|
firstDayOfMonth(): Chronos;
|
|
351
|
-
/** @instance Returns a new Chronos instance set to the last day of the current month. */
|
|
351
|
+
/** @instance Returns a new `Chronos` instance set to the last day of the current month. */
|
|
352
352
|
lastDayOfMonth(): Chronos;
|
|
353
353
|
/**
|
|
354
|
-
* @instance Returns a new Chronos instance at the start of a given unit.
|
|
354
|
+
* @instance Returns a new `Chronos` instance at the start of a given unit.
|
|
355
355
|
* @param unit The unit to reset (e.g., year, month, day).
|
|
356
356
|
* @param weekStartsOn Optional: Day the week starts on (0 = Sunday, 1 = Monday). Applicable if week day is required. Default is `0`.
|
|
357
357
|
*/
|
|
358
358
|
startOf(unit: TimeUnit, weekStartsOn?: Enumerate<7>): Chronos;
|
|
359
359
|
/**
|
|
360
|
-
* @instance Returns a new Chronos instance at the end of a given unit.
|
|
360
|
+
* @instance Returns a new `Chronos` instance at the end of a given unit.
|
|
361
361
|
* @param unit The unit to adjust (e.g., year, month, day).
|
|
362
362
|
* @param weekStartsOn Optional: Day the week starts on (0 = Sunday, 1 = Monday). Applicable if week day is required. Default is `0`.
|
|
363
363
|
*/
|
|
364
364
|
endOf(unit: TimeUnit, weekStartsOn?: Enumerate<7>): Chronos;
|
|
365
365
|
/**
|
|
366
|
-
* @instance Returns a new Chronos instance with the specified unit added.
|
|
366
|
+
* @instance Returns a new `Chronos` instance with the specified unit added.
|
|
367
367
|
* @param number The number of time unit to add (can be negative).
|
|
368
368
|
* @param unit The time unit to add.
|
|
369
369
|
*/
|
|
370
370
|
add(number: number, unit: TimeUnit): Chronos;
|
|
371
371
|
/**
|
|
372
|
-
* @instance Returns a new Chronos instance with the specified unit subtracted.
|
|
372
|
+
* @instance Returns a new `Chronos` instance with the specified unit subtracted.
|
|
373
373
|
* @param number The number of time unit to subtract (can be negative).
|
|
374
374
|
* @param unit The time unit to add.
|
|
375
375
|
*/
|
|
@@ -380,7 +380,7 @@ export declare class Chronos {
|
|
|
380
380
|
*/
|
|
381
381
|
get(unit: TimeUnit): number;
|
|
382
382
|
/**
|
|
383
|
-
* @instance Returns a new Chronos instance with the specified unit set to the given value.
|
|
383
|
+
* @instance Returns a new `Chronos` instance with the specified unit set to the given value.
|
|
384
384
|
* @param unit The unit to modify.
|
|
385
385
|
* @param value The value to set for the unit.
|
|
386
386
|
*/
|
|
@@ -403,7 +403,7 @@ export declare class Chronos {
|
|
|
403
403
|
* This method assumes ISO week logic, where week 1 is the week containing January 4th.
|
|
404
404
|
*
|
|
405
405
|
* @param week The ISO week number (1–53) to set the date to.
|
|
406
|
-
* @returns A new Chronos instance set to the start (Monday) of the specified week.
|
|
406
|
+
* @returns A new `Chronos` instance set to the start (Monday) of the specified week.
|
|
407
407
|
*/
|
|
408
408
|
setWeek(week: NumberRange<1, 53>): Chronos;
|
|
409
409
|
/**
|
|
@@ -462,7 +462,7 @@ export declare class Chronos {
|
|
|
462
462
|
/**
|
|
463
463
|
* @instance Returns the system's current UTC offset formatted as `+06:00` or `-07:00`.
|
|
464
464
|
*
|
|
465
|
-
* - *Unlike `Date.prototype.getTimezoneOffset()
|
|
465
|
+
* - *Unlike JavaScript's {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset `Date.prototype.getTimezoneOffset()`}, which returns the offset in minutes **behind** UTC (positive for locations west of UTC and negative for east), this method returns the more intuitive sign format used in time zone representations (e.g., `+06:00` means 6 hours **ahead** of UTC).*
|
|
466
466
|
*
|
|
467
467
|
* @returns The (local) system's UTC offset in `±HH:mm` format.
|
|
468
468
|
*/
|
|
@@ -470,7 +470,7 @@ export declare class Chronos {
|
|
|
470
470
|
/**
|
|
471
471
|
* @instance Returns the timezone offset of this `Chronos` instance in `+06:00` or `-07:00` format maintaining current timezone.
|
|
472
472
|
*
|
|
473
|
-
* - *Unlike
|
|
473
|
+
* - *Unlike JavaScript's {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset Date.prototype.getTimezoneOffset()}, which returns the offset in minutes **behind** UTC (positive for locations west of UTC and negative for east), this method returns the more intuitive sign format used in time zone representations (e.g., `+06:00` means 6 hours **ahead** of UTC).*
|
|
474
474
|
*
|
|
475
475
|
* @returns The timezone offset string in `±HH:mm` format maintaining the current timezone regardless of system having different one.
|
|
476
476
|
*/
|
|
@@ -478,7 +478,7 @@ export declare class Chronos {
|
|
|
478
478
|
/**
|
|
479
479
|
* @instance Returns the system's UTC offset in minutes.
|
|
480
480
|
*
|
|
481
|
-
* - *Unlike JavaScript's
|
|
481
|
+
* - *Unlike JavaScript's {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset Date.prototype.getTimezoneOffset()}, this method returns a positive value if the local time is ahead of UTC, and negative if behind UTC.*
|
|
482
482
|
*
|
|
483
483
|
* For example, for `UTC+06:00`, this returns `360`; for `UTC-05:30`, this returns `-330`.
|
|
484
484
|
*
|
|
@@ -488,7 +488,7 @@ export declare class Chronos {
|
|
|
488
488
|
/**
|
|
489
489
|
* @instance Returns the current `Chronos` instance's UTC offset in minutes.
|
|
490
490
|
*
|
|
491
|
-
* This reflects the parsed or stored offset used internally by Chronos and follows the same
|
|
491
|
+
* This reflects the parsed or stored offset used internally by `Chronos` and follows the same
|
|
492
492
|
* sign convention: positive for timezones ahead of UTC, negative for behind.
|
|
493
493
|
*
|
|
494
494
|
* @returns The UTC offset in minutes maintaining the current timezone regardless of system having different one.
|
|
@@ -504,28 +504,10 @@ export declare class Chronos {
|
|
|
504
504
|
* - If no match is found (which is rare), it falls back to returning the UTC offset (e.g. `"UTC+06:00"`).
|
|
505
505
|
*/
|
|
506
506
|
getTimeZoneName(utc?: UTCOffSet): LooseLiteral<UTCOffSet>;
|
|
507
|
-
/** @instance Returns new Chronos instance in UTC */
|
|
507
|
+
/** @instance Returns new `Chronos` instance in UTC */
|
|
508
508
|
toUTC(): Chronos;
|
|
509
|
-
/** @instance Returns new Chronos instance in local time */
|
|
509
|
+
/** @instance Returns new `Chronos` instance in local time */
|
|
510
510
|
toLocal(): Chronos;
|
|
511
|
-
/**
|
|
512
|
-
* @instance Rounds the current date-time to the nearest specified unit and interval.
|
|
513
|
-
*
|
|
514
|
-
* - *Rounding is based on proximity to the start or end of the specified unit.*
|
|
515
|
-
* - *For example, rounding `2025-05-23` by 'day' returns either midnight of May 23 or May 24, depending on the time of day.*
|
|
516
|
-
*
|
|
517
|
-
* @param unit - The time unit to round to (`year`, `month`, `week`, `day`, `hour`, `minute`, `second`, `millisecond`).
|
|
518
|
-
* @param nearest - Optional granularity of rounding. (Defaults to `1`).
|
|
519
|
-
*
|
|
520
|
-
* @returns A new `Chronos` instance at the nearest rounded point in time. For wrong unit returns current instance.
|
|
521
|
-
*
|
|
522
|
-
* @remarks
|
|
523
|
-
* - Rounding for `'month'` is based on how far into the month the date is. If past the midpoint, it rounds to the next month.
|
|
524
|
-
* - Month indices are 0-based internally (January = 0), but the resulting date reflects the correct calendar month.
|
|
525
|
-
* - For `'week'` unit, rounding is performed by comparing proximity to the start and end of the ISO week (Monday to Sunday).
|
|
526
|
-
* - If the date is closer to the next Monday, it rounds forward; otherwise, it rounds back to the previous Monday.
|
|
527
|
-
*/
|
|
528
|
-
round(unit: TimeUnit, nearest?: number): Chronos;
|
|
529
511
|
/**
|
|
530
512
|
* @instance Returns the full time duration breakdown between current input (start) and another time (to).
|
|
531
513
|
* @param toTime The time to compare with. Defaults to now.
|
|
@@ -535,14 +517,14 @@ export declare class Chronos {
|
|
|
535
517
|
duration(toTime?: ChronosInput, absolute?: boolean): TimeDuration;
|
|
536
518
|
/**
|
|
537
519
|
* @instance Returns the name of the current day or optional day index.
|
|
538
|
-
* @param index Optional day index (0–6
|
|
539
|
-
* @returns Name of the weekday.
|
|
520
|
+
* @param index Optional day index (`0–6`, where `0` is `Sunday`) to override current day.
|
|
521
|
+
* @returns Name of the weekday, e.g., `'Monday'`, `'Tuesday'` etc.
|
|
540
522
|
*/
|
|
541
523
|
day(index?: Enumerate<7>): WeekDay;
|
|
542
524
|
/**
|
|
543
525
|
* @instance Returns the name of the current month or optional month index.
|
|
544
|
-
* @param index Optional month index (0–11
|
|
545
|
-
* @returns Name of the month.
|
|
526
|
+
* @param index Optional month index (`0–11`, where `0` is `January`) to override current month.
|
|
527
|
+
* @returns Name of the month, e.g., `'January'`, `'February'` etc.
|
|
546
528
|
*/
|
|
547
529
|
monthName(index?: Enumerate<12>): MonthName;
|
|
548
530
|
/**
|
|
@@ -621,7 +603,7 @@ export declare class Chronos {
|
|
|
621
603
|
* **Example**:
|
|
622
604
|
* ```ts
|
|
623
605
|
* Chronos.parse('23-12-31 15:30:45', 'YY-MM-DD HH:mm:ss');
|
|
624
|
-
* // returns Chronos instance with the parsed date 2023-12-31T15:30:45
|
|
606
|
+
* // returns `Chronos` instance with the parsed date 2023-12-31T15:30:45
|
|
625
607
|
* ```
|
|
626
608
|
*
|
|
627
609
|
* @param dateStr - The date string to be parsed
|
|
@@ -675,14 +657,14 @@ export declare class Chronos {
|
|
|
675
657
|
*/
|
|
676
658
|
static now(): number;
|
|
677
659
|
/**
|
|
678
|
-
* @static Creates a UTC-based Chronos instance.
|
|
660
|
+
* @static Creates a UTC-based `Chronos` instance.
|
|
679
661
|
* If no date is provided, it uses the current date and time.
|
|
680
662
|
*
|
|
681
663
|
* **This is the base time, meaning conversion in other timezone will consider UTC time as the base time.**
|
|
682
664
|
*
|
|
683
665
|
* @param dateLike Optional input date to base the UTC time on.
|
|
684
666
|
* If omitted, the current system date/time is used.
|
|
685
|
-
* @returns A new Chronos instance representing the UTC equivalent of the input.
|
|
667
|
+
* @returns A new `Chronos` instance representing the UTC equivalent of the input.
|
|
686
668
|
*/
|
|
687
669
|
static utc(dateLike?: ChronosInput): Chronos;
|
|
688
670
|
/**
|
|
@@ -789,7 +771,7 @@ export declare class Chronos {
|
|
|
789
771
|
static isDateString(value: unknown): value is string;
|
|
790
772
|
/**
|
|
791
773
|
* @static Checks if the given value is an instance of `Chronos`.
|
|
792
|
-
* - Useful for verifying Chronos objects in type guards or validations.
|
|
774
|
+
* - Useful for verifying `Chronos` objects in type guards or validations.
|
|
793
775
|
* @param value - The value to test.
|
|
794
776
|
* @returns `true` if the value is an instance of `Chronos`, otherwise `false`.
|
|
795
777
|
*/
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TimeUnit } from '../types';
|
|
2
|
+
type ChronosConstructor = import('../Chronos').Chronos;
|
|
3
|
+
type MainChronos = typeof import('../Chronos').Chronos;
|
|
4
|
+
declare module '../Chronos' {
|
|
5
|
+
interface Chronos {
|
|
6
|
+
/**
|
|
7
|
+
* @instance Rounds the current date-time to the nearest specified unit and interval.
|
|
8
|
+
*
|
|
9
|
+
* - *Rounding is based on proximity to the start or end of the specified unit.*
|
|
10
|
+
* - *For example, rounding `2025-05-23` by 'day' returns either midnight of May 23 or May 24, depending on the time of day.*
|
|
11
|
+
*
|
|
12
|
+
* @param unit - The time unit to round to (`year`, `month`, `week`, `day`, `hour`, `minute`, `second`, `millisecond`).
|
|
13
|
+
* @param nearest - Optional granularity of rounding. (Defaults to `1`).
|
|
14
|
+
*
|
|
15
|
+
* @returns A new `Chronos` instance at the nearest rounded point in time. For wrong unit returns current instance.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* - Rounding for `'month'` is based on how far into the month the date is. If past the midpoint, it rounds to the next month.
|
|
19
|
+
* - Month indices are 0-based internally (January = 0), but the resulting date reflects the correct calendar month.
|
|
20
|
+
* - For `'week'` unit, rounding is performed by comparing proximity to the start and end of the ISO week (Monday to Sunday).
|
|
21
|
+
* - If the date is closer to the next Monday, it rounds forward; otherwise, it rounds back to the previous Monday.
|
|
22
|
+
*/
|
|
23
|
+
round(unit: TimeUnit, nearest?: number): ChronosConstructor;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** * Plugin to inject `round` method */
|
|
27
|
+
export declare const roundPlugin: (ChronosClass: MainChronos) => void;
|
|
28
|
+
export {};
|
package/dist/dts/date/types.d.ts
CHANGED
|
@@ -132,7 +132,7 @@ export interface ChronosInternals {
|
|
|
132
132
|
* @param label - Optional UTC offset label
|
|
133
133
|
* @returns A new Chronos instance
|
|
134
134
|
*/
|
|
135
|
-
withOrigin(instance: Chronos, method:
|
|
135
|
+
withOrigin(instance: Chronos, method: PluginMethods, label?: UTCOffSet): Chronos;
|
|
136
136
|
/**
|
|
137
137
|
* * Access to `#toNewDate` private method
|
|
138
138
|
* * Creates a new `Date` object from a Chronos input
|
|
@@ -171,7 +171,9 @@ export type $StaticMethods = {
|
|
|
171
171
|
} ? Method : never;
|
|
172
172
|
}[keyof $Chronos];
|
|
173
173
|
/** * Plugin methods that return `Chronos` instance */
|
|
174
|
-
export type $PluginMethods =
|
|
174
|
+
export type $PluginMethods = 'timeZone' | 'round';
|
|
175
|
+
/** * Plugin methods that return `Chronos` instance + any custom name */
|
|
176
|
+
export type PluginMethods = LooseLiteral<'timeZone' | 'round'>;
|
|
175
177
|
/** Methods (both instance and static) in `Chronos` class that return `Chronos` instance. */
|
|
176
178
|
export type ChronosMethods = $InstanceMethods | $StaticMethods | $PluginMethods;
|
|
177
179
|
/**
|
|
@@ -394,7 +396,7 @@ export interface DateLike {
|
|
|
394
396
|
/**
|
|
395
397
|
* * Options for `Chronos` _static_ method `with()`
|
|
396
398
|
*
|
|
397
|
-
* @remarks Should provide at least one property.
|
|
399
|
+
* @remarks Should provide at least one property, otherwise use the current date and time.
|
|
398
400
|
*/
|
|
399
401
|
export type ChronosWithOptions = Partial<{
|
|
400
402
|
/** The full year (e.g., 2025). Years 0–99 are interpreted as 1900–1999. */
|
package/dist/esm/date/Chronos.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
import { isValidArray } from '../guards/non-primitives.js';
|
|
3
3
|
import { isString } from '../guards/primitives.js';
|
|
4
|
-
import { getOrdinal
|
|
4
|
+
import { getOrdinal } from '../number/utilities.js';
|
|
5
5
|
import { DAYS, INTERNALS, MONTHS, SORTED_TIME_FORMATS, TIME_ZONE_LABELS } from './constants.js';
|
|
6
6
|
import { isLeapYear } from './guards.js';
|
|
7
7
|
import { extractMinutesFromUTC } from './utils.js';
|
|
@@ -429,6 +429,8 @@ export class Chronos {
|
|
|
429
429
|
return t > s && t <= e;
|
|
430
430
|
case '()':
|
|
431
431
|
return t > s && t < e;
|
|
432
|
+
default:
|
|
433
|
+
return false;
|
|
432
434
|
}
|
|
433
435
|
}
|
|
434
436
|
isDST() {
|
|
@@ -733,81 +735,6 @@ export class Chronos {
|
|
|
733
735
|
const localTime = new Date(this.#date.getTime() - relativeOffset * 60 * 1000);
|
|
734
736
|
return new _a(localTime).#withOrigin('toLocal');
|
|
735
737
|
}
|
|
736
|
-
round(unit, nearest = 1) {
|
|
737
|
-
const date = new Date(this.#date);
|
|
738
|
-
switch (unit) {
|
|
739
|
-
case 'millisecond': {
|
|
740
|
-
const rounded = roundToNearest(date.getMilliseconds(), nearest);
|
|
741
|
-
date.setMilliseconds(rounded);
|
|
742
|
-
break;
|
|
743
|
-
}
|
|
744
|
-
case 'second': {
|
|
745
|
-
const fullSecond = date.getSeconds() + date.getMilliseconds() / 1000;
|
|
746
|
-
const rounded = roundToNearest(fullSecond, nearest);
|
|
747
|
-
date.setSeconds(rounded, 0);
|
|
748
|
-
break;
|
|
749
|
-
}
|
|
750
|
-
case 'minute': {
|
|
751
|
-
const fullMinute = date.getMinutes() + date.getSeconds() / 60 + date.getMilliseconds() / 60000;
|
|
752
|
-
const rounded = roundToNearest(fullMinute, nearest);
|
|
753
|
-
date.setMinutes(rounded, 0, 0);
|
|
754
|
-
break;
|
|
755
|
-
}
|
|
756
|
-
case 'hour': {
|
|
757
|
-
const fullHour = date.getHours() +
|
|
758
|
-
date.getMinutes() / 60 +
|
|
759
|
-
date.getSeconds() / 3600 +
|
|
760
|
-
date.getMilliseconds() / 3600000;
|
|
761
|
-
const rounded = roundToNearest(fullHour, nearest);
|
|
762
|
-
date.setHours(rounded, 0, 0, 0);
|
|
763
|
-
break;
|
|
764
|
-
}
|
|
765
|
-
case 'day': {
|
|
766
|
-
const fullDay = date.getDate() +
|
|
767
|
-
(date.getHours() / 24 +
|
|
768
|
-
date.getMinutes() / 1440 +
|
|
769
|
-
date.getSeconds() / 86400 +
|
|
770
|
-
date.getMilliseconds() / 86400000);
|
|
771
|
-
const rounded = roundToNearest(fullDay, nearest);
|
|
772
|
-
date.setDate(rounded);
|
|
773
|
-
date.setHours(0, 0, 0, 0);
|
|
774
|
-
break;
|
|
775
|
-
}
|
|
776
|
-
case 'week': {
|
|
777
|
-
const weekday = this.#date.getDay();
|
|
778
|
-
const offsetToMonday = (weekday + 6) % 7;
|
|
779
|
-
const startOfWeek = new Date(this.#date);
|
|
780
|
-
startOfWeek.setDate(startOfWeek.getDate() - offsetToMonday);
|
|
781
|
-
startOfWeek.setHours(0, 0, 0, 0);
|
|
782
|
-
const endOfWeek = new Date(startOfWeek);
|
|
783
|
-
endOfWeek.setDate(endOfWeek.getDate() + 7);
|
|
784
|
-
const diffToStart = Math.abs(this.#date.getTime() - startOfWeek.getTime());
|
|
785
|
-
const diffToEnd = Math.abs(endOfWeek.getTime() - this.#date.getTime());
|
|
786
|
-
const rounded = diffToEnd < diffToStart ? endOfWeek : startOfWeek;
|
|
787
|
-
return new _a(rounded).#withOrigin('round');
|
|
788
|
-
}
|
|
789
|
-
case 'month': {
|
|
790
|
-
const fullMonth = date.getMonth() + date.getDate() / this.lastDateOfMonth;
|
|
791
|
-
const roundedMonth = roundToNearest(fullMonth, nearest);
|
|
792
|
-
date.setMonth(roundedMonth, 1);
|
|
793
|
-
date.setHours(0, 0, 0, 0);
|
|
794
|
-
break;
|
|
795
|
-
}
|
|
796
|
-
case 'year': {
|
|
797
|
-
const dayOfYear = Math.floor((date.getTime() - new Date(date.getFullYear(), 0, 1).getTime()) / 86400000);
|
|
798
|
-
const isLeap = new Date(date.getFullYear(), 1, 29).getDate() === 29;
|
|
799
|
-
const totalDays = isLeap ? 366 : 365;
|
|
800
|
-
const fullYear = date.getFullYear() + dayOfYear / totalDays;
|
|
801
|
-
const roundedYear = roundToNearest(fullYear, nearest);
|
|
802
|
-
date.setFullYear(roundedYear, 0, 1);
|
|
803
|
-
date.setHours(0, 0, 0, 0);
|
|
804
|
-
break;
|
|
805
|
-
}
|
|
806
|
-
default:
|
|
807
|
-
return this;
|
|
808
|
-
}
|
|
809
|
-
return new _a(date).#withOrigin('round');
|
|
810
|
-
}
|
|
811
738
|
duration(toTime, absolute = true) {
|
|
812
739
|
const now = this.#date;
|
|
813
740
|
const target = this.#toNewDate(toTime);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { roundToNearest } from '../../number/utilities.js';
|
|
2
|
+
import { INTERNALS } from '../constants.js';
|
|
3
|
+
export const roundPlugin = (ChronosClass) => {
|
|
4
|
+
const internal = ChronosClass[INTERNALS];
|
|
5
|
+
ChronosClass.prototype.round = function (unit, nearest = 1) {
|
|
6
|
+
const date = internal.internalDate(this);
|
|
7
|
+
switch (unit) {
|
|
8
|
+
case 'millisecond': {
|
|
9
|
+
const rounded = roundToNearest(date.getMilliseconds(), nearest);
|
|
10
|
+
date.setMilliseconds(rounded);
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
case 'second': {
|
|
14
|
+
const fullSecond = date.getSeconds() + date.getMilliseconds() / 1000;
|
|
15
|
+
const rounded = roundToNearest(fullSecond, nearest);
|
|
16
|
+
date.setSeconds(rounded, 0);
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
case 'minute': {
|
|
20
|
+
const fullMinute = date.getMinutes() + date.getSeconds() / 60 + date.getMilliseconds() / 60000;
|
|
21
|
+
const rounded = roundToNearest(fullMinute, nearest);
|
|
22
|
+
date.setMinutes(rounded, 0, 0);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
case 'hour': {
|
|
26
|
+
const fullHour = date.getHours() +
|
|
27
|
+
date.getMinutes() / 60 +
|
|
28
|
+
date.getSeconds() / 3600 +
|
|
29
|
+
date.getMilliseconds() / 3600000;
|
|
30
|
+
const rounded = roundToNearest(fullHour, nearest);
|
|
31
|
+
date.setHours(rounded, 0, 0, 0);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
case 'day': {
|
|
35
|
+
const fullDay = date.getDate() +
|
|
36
|
+
(date.getHours() / 24 +
|
|
37
|
+
date.getMinutes() / 1440 +
|
|
38
|
+
date.getSeconds() / 86400 +
|
|
39
|
+
date.getMilliseconds() / 86400000);
|
|
40
|
+
const rounded = roundToNearest(fullDay, nearest);
|
|
41
|
+
date.setDate(rounded);
|
|
42
|
+
date.setHours(0, 0, 0, 0);
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case 'week': {
|
|
46
|
+
const weekday = date.getDay();
|
|
47
|
+
const offsetToMonday = (weekday + 6) % 7;
|
|
48
|
+
const startOfWeek = new Date(date);
|
|
49
|
+
startOfWeek.setDate(startOfWeek.getDate() - offsetToMonday);
|
|
50
|
+
startOfWeek.setHours(0, 0, 0, 0);
|
|
51
|
+
const endOfWeek = new Date(startOfWeek);
|
|
52
|
+
endOfWeek.setDate(endOfWeek.getDate() + 7);
|
|
53
|
+
const diffToStart = Math.abs(date.getTime() - startOfWeek.getTime());
|
|
54
|
+
const diffToEnd = Math.abs(endOfWeek.getTime() - date.getTime());
|
|
55
|
+
const rounded = diffToEnd < diffToStart ? endOfWeek : startOfWeek;
|
|
56
|
+
return internal.withOrigin(new ChronosClass(rounded), 'round');
|
|
57
|
+
}
|
|
58
|
+
case 'month': {
|
|
59
|
+
const fullMonth = date.getMonth() + date.getDate() / this.lastDateOfMonth;
|
|
60
|
+
const roundedMonth = roundToNearest(fullMonth, nearest);
|
|
61
|
+
date.setMonth(roundedMonth, 1);
|
|
62
|
+
date.setHours(0, 0, 0, 0);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case 'year': {
|
|
66
|
+
const dayOfYear = Math.floor((date.getTime() - new Date(date.getFullYear(), 0, 1).getTime()) / 86400000);
|
|
67
|
+
const isLeap = new Date(date.getFullYear(), 1, 29).getDate() === 29;
|
|
68
|
+
const totalDays = isLeap ? 366 : 365;
|
|
69
|
+
const fullYear = date.getFullYear() + dayOfYear / totalDays;
|
|
70
|
+
const roundedYear = roundToNearest(fullYear, nearest);
|
|
71
|
+
date.setFullYear(roundedYear, 0, 1);
|
|
72
|
+
date.setHours(0, 0, 0, 0);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
default:
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
return internal.withOrigin(new ChronosClass(date), 'round');
|
|
79
|
+
};
|
|
80
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nhb-toolbox",
|
|
3
|
-
"version": "4.21.
|
|
3
|
+
"version": "4.21.11",
|
|
4
4
|
"description": "A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -203,6 +203,11 @@
|
|
|
203
203
|
"import": "./dist/esm/date/plugins/relativeTimePlugin.js",
|
|
204
204
|
"require": "./dist/cjs/date/plugins/relativeTimePlugin.js"
|
|
205
205
|
},
|
|
206
|
+
"./plugins/roundPlugin": {
|
|
207
|
+
"types": "./dist/dts/date/plugins/roundPlugin.d.ts",
|
|
208
|
+
"import": "./dist/esm/date/plugins/roundPlugin.js",
|
|
209
|
+
"require": "./dist/cjs/date/plugins/roundPlugin.js"
|
|
210
|
+
},
|
|
206
211
|
"./plugins/seasonPlugin": {
|
|
207
212
|
"types": "./dist/dts/date/plugins/seasonPlugin.d.ts",
|
|
208
213
|
"import": "./dist/esm/date/plugins/seasonPlugin.js",
|
|
@@ -284,6 +289,9 @@
|
|
|
284
289
|
"plugins/relativeTimePlugin": [
|
|
285
290
|
"dist/dts/date/plugins/relativeTimePlugin.d.ts"
|
|
286
291
|
],
|
|
292
|
+
"plugins/roundPlugin": [
|
|
293
|
+
"dist/dts/date/plugins/roundPlugin.d.ts"
|
|
294
|
+
],
|
|
287
295
|
"plugins/seasonPlugin": [
|
|
288
296
|
"dist/dts/date/plugins/seasonPlugin.d.ts"
|
|
289
297
|
],
|