@williamthorsen/toolbelt.datetime 4.0.1 → 4.0.3
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 +16 -0
- package/dist/esm/2-draft/TimeUnit.js +2 -4
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## 4.0.3 — 2026-08-24
|
|
6
|
+
|
|
7
|
+
### Dependency updates
|
|
8
|
+
|
|
9
|
+
- Bumped `@williamthorsen/toolbelt.numbers` to 7.0.1
|
|
10
|
+
|
|
11
|
+
## 4.0.2 — 2026-08-21
|
|
12
|
+
|
|
13
|
+
### Bug fixes
|
|
14
|
+
|
|
15
|
+
- Adopt `round` in `TimeUnit.convert` and repair its same-unit path (#192)
|
|
16
|
+
|
|
17
|
+
Fixes an issue where `TimeUnit.convert` ignored both `decimalPlaces` and `throwOnFractional` whenever the source and target units were the same, returning the amount untouched.
|
|
18
|
+
|
|
19
|
+
Separately, replaces the method's hand-rolled decimal rounding with `round` from `@williamthorsen/toolbelt.numbers/candidate`, which gives `datetime` its first runtime dependency.
|
|
20
|
+
|
|
5
21
|
## 4.0.1 — 2026-08-13
|
|
6
22
|
|
|
7
23
|
### Tooling
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { round } from '@williamthorsen/toolbelt.numbers/candidate';
|
|
1
2
|
export class TimeUnit {
|
|
2
3
|
inMillis;
|
|
3
4
|
static Millis = new TimeUnit(1, { singular: 'millisecond', abbrev: 'ms' });
|
|
@@ -23,9 +24,6 @@ export class TimeUnit {
|
|
|
23
24
|
}
|
|
24
25
|
static convert(amount, fromUnit, toUnit, options = {}) {
|
|
25
26
|
const { decimalPlaces, throwOnFractional } = options;
|
|
26
|
-
if (fromUnit.inMillis === toUnit.inMillis) {
|
|
27
|
-
return amount;
|
|
28
|
-
}
|
|
29
27
|
const value = fromUnit.inMillis > toUnit.inMillis
|
|
30
28
|
? amount * (fromUnit.inMillis / toUnit.inMillis)
|
|
31
29
|
: amount / (toUnit.inMillis / fromUnit.inMillis);
|
|
@@ -33,7 +31,7 @@ export class TimeUnit {
|
|
|
33
31
|
throw new Error(`${fromUnit.formatLabeledCount(amount)} cannot be converted into an exact whole number of ${toUnit.plural}.`);
|
|
34
32
|
}
|
|
35
33
|
if (decimalPlaces !== undefined) {
|
|
36
|
-
return
|
|
34
|
+
return round(value, decimalPlaces);
|
|
37
35
|
}
|
|
38
36
|
return value;
|
|
39
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@williamthorsen/toolbelt.datetime",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Date and time utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"date",
|
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
"dist/*",
|
|
44
44
|
"CHANGELOG.md"
|
|
45
45
|
],
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@williamthorsen/toolbelt.numbers": "7.0.1"
|
|
48
|
+
},
|
|
46
49
|
"engines": {
|
|
47
50
|
"node": ">=24.0.0"
|
|
48
51
|
},
|