@williamthorsen/toolbelt.datetime 4.0.0 → 4.0.2
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 +19 -0
- package/README.md +6 -4
- package/dist/esm/2-draft/TimeUnit.js +2 -4
- package/package.json +16 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## 4.0.2 — 2026-08-21
|
|
6
|
+
|
|
7
|
+
### Bug fixes
|
|
8
|
+
|
|
9
|
+
- Adopt `round` in `TimeUnit.convert` and repair its same-unit path (#192)
|
|
10
|
+
|
|
11
|
+
Fixes an issue where `TimeUnit.convert` ignored both `decimalPlaces` and `throwOnFractional` whenever the source and target units were the same, returning the amount untouched.
|
|
12
|
+
|
|
13
|
+
Separately, replaces the method's hand-rolled decimal rounding with `round` from `@williamthorsen/toolbelt.numbers/candidate`, which gives `datetime` its first runtime dependency.
|
|
14
|
+
|
|
15
|
+
## 4.0.1 — 2026-08-13
|
|
16
|
+
|
|
17
|
+
### Tooling
|
|
18
|
+
|
|
19
|
+
- Remove redundant .gitignore files
|
|
20
|
+
- Populate manifest metadata and adopt a pnpm catalog (#140)
|
|
21
|
+
|
|
22
|
+
Adopts a pnpm catalog to avoid specifying the version of a common dependency in multiple places. Separately, fixes violations of newly activated `package-json` lint rules. Missing values have been added to `package.json` fields across the repo, and package descriptions are improved.
|
|
23
|
+
|
|
5
24
|
## 4.0.0 — 2026-08-12
|
|
6
25
|
|
|
7
26
|
### Features
|
package/README.md
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
Date and time utilities.
|
|
4
4
|
|
|
5
5
|
<!-- section:release-notes -->
|
|
6
|
-
## Release notes — v4.0.
|
|
6
|
+
## Release notes — v4.0.2 (2026-08-21)
|
|
7
7
|
|
|
8
|
-
###
|
|
8
|
+
### Bug fixes
|
|
9
9
|
|
|
10
|
-
-
|
|
10
|
+
- Adopt `round` in `TimeUnit.convert` and repair its same-unit path (#192)
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Fixes an issue where `TimeUnit.convert` ignored both `decimalPlaces` and `throwOnFractional` whenever the source and target units were the same, returning the amount untouched.
|
|
13
|
+
|
|
14
|
+
Separately, replaces the method's hand-rolled decimal rounding with `round` from `@williamthorsen/toolbelt.numbers/candidate`, which gives `datetime` its first runtime dependency.
|
|
13
15
|
<!-- /section:release-notes -->
|
|
14
16
|
|
|
15
17
|
## Installation
|
|
@@ -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,8 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@williamthorsen/toolbelt.datetime",
|
|
3
|
-
"version": "4.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"keywords": [
|
|
3
|
+
"version": "4.0.2",
|
|
4
|
+
"description": "Date and time utilities",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"date",
|
|
7
|
+
"datetime",
|
|
8
|
+
"duration",
|
|
9
|
+
"esm",
|
|
10
|
+
"timer",
|
|
11
|
+
"toolbelt",
|
|
12
|
+
"typescript",
|
|
13
|
+
"utilities"
|
|
14
|
+
],
|
|
6
15
|
"homepage": "https://github.com/williamthorsen/toolbelt/tree/main/packages/datetime#readme",
|
|
7
16
|
"bugs": {
|
|
8
17
|
"url": "https://github.com/williamthorsen/toolbelt/issues"
|
|
@@ -14,6 +23,7 @@
|
|
|
14
23
|
},
|
|
15
24
|
"license": "ISC",
|
|
16
25
|
"author": "William Thorsen <william@thorsen.dev> (https://github.com/williamthorsen)",
|
|
26
|
+
"sideEffects": false,
|
|
17
27
|
"type": "module",
|
|
18
28
|
"exports": {
|
|
19
29
|
".": {
|
|
@@ -33,6 +43,9 @@
|
|
|
33
43
|
"dist/*",
|
|
34
44
|
"CHANGELOG.md"
|
|
35
45
|
],
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@williamthorsen/toolbelt.numbers": "7.0.0"
|
|
48
|
+
},
|
|
36
49
|
"engines": {
|
|
37
50
|
"node": ">=24.0.0"
|
|
38
51
|
},
|