Skip to content

feat: add toTemporalDuration() converter#56

Merged
bendrucker merged 1 commit into
masterfrom
temporal-duration
Jun 29, 2026
Merged

feat: add toTemporalDuration() converter#56
bendrucker merged 1 commit into
masterfrom
temporal-duration

Conversation

@bendrucker

@bendrucker bendrucker commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Adds an opt-in interval.toTemporalDuration() that returns a Temporal.Duration, giving interoperability with the standard type for consumers who want it. Closes #55.

This is additive and zero-dependency rather than a return-type change. Temporal is not yet broadly available: Node 24 (current LTS) ships without it, and Node 26 only becomes LTS in October 2026. Switching the default output now would be premature and breaking. The method feature-detects globalThis.Temporal and throws a clear error when it is absent, pointing the caller at the Node 26 baseline or a polyfill assigned to the global. Changing the default return type is deferred to a future major once Node 26 is LTS and Node 24 nears EOL.

PostgresInterval's fractional milliseconds float is split back into integer milliseconds + microseconds fields at Postgres's native microsecond precision. There are no weeks (default Postgres output normalizes them to days) or nanoseconds.

Mixed-sign intervals like 1 mon -1 days throw a RangeError. Temporal.Duration requires all fields to share one sign, and rather than invent a reconciliation we pass the fields straight through and let Temporal's own validation reject them. This is documented and covered by a test.

Adds an opt-in PostgresInterval.prototype.toTemporalDuration() that returns a Temporal.Duration, feature-detected via globalThis.Temporal with no new dependency. Mixed-sign intervals throw RangeError from Temporal's own validation.

Refreshes the CI matrix to Node 20/22/24/26 so the Temporal path runs, and bumps the checkout/setup-node action pins. Closes #55.
@bendrucker bendrucker merged commit ffe9ba1 into master Jun 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrating towards Temporal.Duration

1 participant