feat: add toTemporalDuration() converter#56
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an opt-in
interval.toTemporalDuration()that returns aTemporal.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.Temporaland 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 fractionalmillisecondsfloat is split back into integermilliseconds+microsecondsfields at Postgres's native microsecond precision. There are noweeks(default Postgres output normalizes them to days) ornanoseconds.Mixed-sign intervals like
1 mon -1 daysthrow aRangeError.Temporal.Durationrequires 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.