@williamthorsen/toolbelt.datetime 3.3.0 → 4.0.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/CHANGELOG.md +14 -0
- package/README.md +3 -9
- package/dist/esm/1-proposed/formatDuration.js +1 -1
- package/dist/esm/1-proposed/index.d.ts +2 -2
- package/dist/esm/1-proposed/index.js +2 -2
- package/dist/esm/1-proposed/listDecadesContainingRange.d.ts +5 -0
- package/dist/esm/1-proposed/{getDecadesContainingRange.js → listDecadesContainingRange.js} +1 -1
- package/dist/esm/1-proposed/{getDecadesContainingYears.d.ts → listDecadesContainingYears.d.ts} +1 -1
- package/dist/esm/1-proposed/{getDecadesContainingYears.js → listDecadesContainingYears.js} +1 -1
- package/dist/esm/1-proposed/types.d.ts +1 -1
- package/dist/esm/2-draft/TimeUnit.d.ts +2 -2
- package/dist/esm/2-draft/TimeUnit.js +4 -4
- package/package.json +1 -1
- package/dist/esm/1-proposed/getDecadesContainingRange.d.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## 4.0.0 — 2026-08-12
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- 🚨 **Breaking:** Rename get* functions by return kind and verb specificity (#119)
|
|
10
|
+
|
|
11
|
+
Renames thirteen functions across various packages to align with a consistent naming pattern.
|
|
12
|
+
|
|
13
|
+
### Refactoring
|
|
14
|
+
|
|
15
|
+
- Align stray modules with layout and TypeScript conventions (#118)
|
|
16
|
+
|
|
17
|
+
Aligns all packages with code-layout and annotation conventions, ending a handful of long-standing exceptions. Documentation has been updated to make the conventions clear.
|
|
18
|
+
|
|
5
19
|
## 3.3.0 — 2026-08-08
|
|
6
20
|
|
|
7
21
|
### Features
|
package/README.md
CHANGED
|
@@ -3,19 +3,13 @@
|
|
|
3
3
|
Date and time utilities.
|
|
4
4
|
|
|
5
5
|
<!-- section:release-notes -->
|
|
6
|
-
## Release notes —
|
|
6
|
+
## Release notes — v4.0.0 (2026-08-12)
|
|
7
7
|
|
|
8
8
|
### Features
|
|
9
9
|
|
|
10
|
-
-
|
|
10
|
+
- 🚨 **Breaking:** Rename get* functions by return kind and verb specificity (#119)
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
`TimeUnit`, in `@williamthorsen/toolbelt.datetime/draft`, now converts to a coarser unit exactly: an hour expressed in milliseconds converts to one hour, where it previously came back a fraction short and could truncate to zero. `TimeUnit` also now exposes its units as a list ordered from coarsest to finest.
|
|
15
|
-
|
|
16
|
-
- Use underscore separator at 4 digits or more
|
|
17
|
-
|
|
18
|
-
Changes the `unicorn/numeric-separators-style` rule config so that separators are consistently used in base 10 numbers, instead of exempting numbers of 5 digits or less.
|
|
12
|
+
Renames thirteen functions across various packages to align with a consistent naming pattern.
|
|
19
13
|
<!-- /section:release-notes -->
|
|
20
14
|
|
|
21
15
|
## Installation
|
|
@@ -4,7 +4,7 @@ export function formatDuration(milliseconds, options = {}) {
|
|
|
4
4
|
const { maxUnits = 1 } = options;
|
|
5
5
|
assertValidArguments(milliseconds, maxUnits);
|
|
6
6
|
const components = selectComponents(milliseconds, maxUnits);
|
|
7
|
-
return components.map(({ count, unit }) => unit.
|
|
7
|
+
return components.map(({ count, unit }) => unit.formatLabeledCount(count, { format: 'short' })).join(' ');
|
|
8
8
|
}
|
|
9
9
|
function selectComponents(milliseconds, maxUnits) {
|
|
10
10
|
let leadingIndex = selectLeadingIndex(milliseconds);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { formatDuration, type FormatDurationOptions } from './formatDuration.js';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { listDecadesContainingRange } from './listDecadesContainingRange.js';
|
|
3
|
+
export { listDecadesContainingYears } from './listDecadesContainingYears.js';
|
|
4
4
|
export { startTimer } from './startTimer.js';
|
|
5
5
|
export * from './types.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { formatDuration } from "./formatDuration.js";
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { listDecadesContainingRange } from "./listDecadesContainingRange.js";
|
|
3
|
+
export { listDecadesContainingYears } from "./listDecadesContainingYears.js";
|
|
4
4
|
export { startTimer } from "./startTimer.js";
|
|
5
5
|
export * from "./types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { Decade } from './
|
|
1
|
+
export type { Decade } from './listDecadesContainingYears.js';
|
|
@@ -11,8 +11,8 @@ export declare class TimeUnit {
|
|
|
11
11
|
readonly singular: string;
|
|
12
12
|
private constructor();
|
|
13
13
|
static convert(amount: number, fromUnit: TimeUnit, toUnit: TimeUnit, options?: TimeUnitConversionOptions): number;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
formatLabeledCount(amount: number, options?: TimeUnitLabelOptions): string;
|
|
15
|
+
inflectLabel(amount: number): string;
|
|
16
16
|
toString(): string;
|
|
17
17
|
}
|
|
18
18
|
export interface TimeUnitConversionOptions {
|
|
@@ -30,20 +30,20 @@ export class TimeUnit {
|
|
|
30
30
|
? amount * (fromUnit.inMillis / toUnit.inMillis)
|
|
31
31
|
: amount / (toUnit.inMillis / fromUnit.inMillis);
|
|
32
32
|
if (throwOnFractional && !Number.isSafeInteger(value)) {
|
|
33
|
-
throw new Error(`${fromUnit.
|
|
33
|
+
throw new Error(`${fromUnit.formatLabeledCount(amount)} cannot be converted into an exact whole number of ${toUnit.plural}.`);
|
|
34
34
|
}
|
|
35
35
|
if (decimalPlaces !== undefined) {
|
|
36
36
|
return Math.round(value * 10 ** decimalPlaces) / 10 ** decimalPlaces;
|
|
37
37
|
}
|
|
38
38
|
return value;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
formatLabeledCount(amount, options = {}) {
|
|
41
41
|
if (options.format === 'short') {
|
|
42
42
|
return `${amount}${this.abbrev}`;
|
|
43
43
|
}
|
|
44
|
-
return `${amount} ${this.
|
|
44
|
+
return `${amount} ${this.inflectLabel(amount)}`;
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
inflectLabel(amount) {
|
|
47
47
|
return amount === 1 ? this.singular : this.plural;
|
|
48
48
|
}
|
|
49
49
|
toString() {
|
package/package.json
CHANGED