@williamthorsen/toolbelt.datetime 3.3.0 → 4.0.1

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 CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 4.0.1 — 2026-08-13
6
+
7
+ ### Tooling
8
+
9
+ - Remove redundant .gitignore files
10
+ - Populate manifest metadata and adopt a pnpm catalog (#140)
11
+
12
+ 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.
13
+
14
+ ## 4.0.0 — 2026-08-12
15
+
16
+ ### Features
17
+
18
+ - 🚨 **Breaking:** Rename get* functions by return kind and verb specificity (#119)
19
+
20
+ Renames thirteen functions across various packages to align with a consistent naming pattern.
21
+
22
+ ### Refactoring
23
+
24
+ - Align stray modules with layout and TypeScript conventions (#118)
25
+
26
+ 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.
27
+
5
28
  ## 3.3.0 — 2026-08-08
6
29
 
7
30
  ### Features
package/README.md CHANGED
@@ -2,21 +2,7 @@
2
2
 
3
3
  Date and time utilities.
4
4
 
5
- <!-- section:release-notes -->
6
- ## Release notes — v3.3.0 (2026-08-08)
7
-
8
- ### Features
9
-
10
- - Add elapsed-time measurement and multi-unit duration formatting (#95)
11
-
12
- Adds two functions for measuring and formatting durations to `@williamthorsen/toolbelt.datetime` at the "proposed" stage. `startTimer` measures how long a span of work takes, returning a reader that reports whole elapsed milliseconds and can be read repeatedly during the span; it measures independently of the system clock, so a clock adjustment partway through does not skew the result. `formatDuration` renders a millisecond count as a short labeled duration and picks the unit itself, so 240,000 becomes `4m`; an option raises the ceiling on how many components appear, so 250,300 becomes `4m 10s 300ms`.
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.
19
- <!-- /section:release-notes -->
5
+ <!-- section:release-notes --><!-- /section:release-notes -->
20
6
 
21
7
  ## Installation
22
8
 
@@ -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.getLabeledCount(count, { format: 'short' })).join(' ');
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 { getDecadesContainingRange } from './getDecadesContainingRange.js';
3
- export { getDecadesContainingYears } from './getDecadesContainingYears.js';
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 { getDecadesContainingRange } from "./getDecadesContainingRange.js";
3
- export { getDecadesContainingYears } from "./getDecadesContainingYears.js";
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";
@@ -0,0 +1,5 @@
1
+ import type { Decade } from './listDecadesContainingYears.js';
2
+ export declare function listDecadesContainingRange(range: {
3
+ start: number;
4
+ end: number;
5
+ }): Decade[];
@@ -1,4 +1,4 @@
1
- export function getDecadesContainingRange(range) {
1
+ export function listDecadesContainingRange(range) {
2
2
  const { start, end } = range;
3
3
  if (start < 0 || end < 0) {
4
4
  throw new RangeError(`Negative years are not supported: start = ${start}, end = ${end}.`);
@@ -1,4 +1,4 @@
1
- export declare function getDecadesContainingYears(years: number[]): Decade[];
1
+ export declare function listDecadesContainingYears(years: number[]): Decade[];
2
2
  export interface Decade {
3
3
  start: number;
4
4
  end: number;
@@ -1,4 +1,4 @@
1
- export function getDecadesContainingYears(years) {
1
+ export function listDecadesContainingYears(years) {
2
2
  const uniqueYears = [...new Set(years)].toSorted((a, b) => a - b);
3
3
  const decadesMap = new Map();
4
4
  const [firstYear] = uniqueYears;
@@ -1 +1 @@
1
- export type { Decade } from './getDecadesContainingYears.js';
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
- getLabeledCount(amount: number, options?: TimeUnitLabelOptions): string;
15
- getInflectedLabel(amount: number): string;
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.getLabeledCount(amount)} cannot be converted into an exact whole number of ${toUnit.plural}.`);
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
- getLabeledCount(amount, options = {}) {
40
+ formatLabeledCount(amount, options = {}) {
41
41
  if (options.format === 'short') {
42
42
  return `${amount}${this.abbrev}`;
43
43
  }
44
- return `${amount} ${this.getInflectedLabel(amount)}`;
44
+ return `${amount} ${this.inflectLabel(amount)}`;
45
45
  }
46
- getInflectedLabel(amount) {
46
+ inflectLabel(amount) {
47
47
  return amount === 1 ? this.singular : this.plural;
48
48
  }
49
49
  toString() {
package/package.json CHANGED
@@ -1,8 +1,17 @@
1
1
  {
2
2
  "name": "@williamthorsen/toolbelt.datetime",
3
- "version": "3.3.0",
4
- "description": "API",
5
- "keywords": [],
3
+ "version": "4.0.1",
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
  ".": {
@@ -1,5 +0,0 @@
1
- import type { Decade } from './getDecadesContainingYears.js';
2
- export declare function getDecadesContainingRange(range: {
3
- start: number;
4
- end: number;
5
- }): Decade[];