-
-
Notifications
You must be signed in to change notification settings - Fork 99
Accept Temporal values from any spec-conformant implementation
#768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f26568f
Bump the TypeScript catalog to 6.0
dahlia 554ebda
Accept Temporal values from any spec-conformant implementation
dahlia b806d18
Stop importing @js-temporal/polyfill from generated .d.ts files
dahlia e49441f
Mention the Temporal fix and TypeScript 6 requirement in the changelog
dahlia c2433bd
Verify a distinctive Temporal property in addition to the toStringTag
dahlia 6761bd1
Expose the Temporal type guards under a dedicated subpath export
dahlia fd6833e
Split the polyfill banner in the remaining packages too
dahlia 0badf55
Refresh vocab-tools codegen snapshots for the Temporal helpers
dahlia 43c843c
Add PR links to the changelog
dahlia aa2f35c
Move the esnext.temporal reference out of vocab-runtime's source
dahlia fe23bcf
Use Object.prototype.toString for Temporal guards
dahlia a9096a7
Make the docs build pass under TypeScript 6
dahlia 4e6852a
Tighten Temporal guards with typeof checks
dahlia 15f0d34
Always validate KV cache rule TTLs via from()
dahlia fd023a2
Reject Temporal spoofs with default toString
dahlia b14a2af
Restrict Duration sign to the spec set (-1, 0, 1)
dahlia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { Temporal } from "@js-temporal/polyfill"; | ||
| import { strictEqual } from "node:assert"; | ||
| import { test } from "node:test"; | ||
| import { isTemporalDuration, isTemporalInstant } from "./temporal.ts"; | ||
|
dahlia marked this conversation as resolved.
|
||
|
|
||
| test("isTemporalInstant() accepts polyfill instances", () => { | ||
| strictEqual( | ||
| isTemporalInstant(Temporal.Instant.from("2026-05-14T00:00:00Z")), | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| test("isTemporalInstant() accepts spec-compliant non-polyfill objects", () => { | ||
| // Mimics the shape of a native `Temporal.Instant` from a host that does | ||
| // not share class identity with the bundled polyfill. | ||
| const nativeLike = Object.create(null, { | ||
| [Symbol.toStringTag]: { value: "Temporal.Instant" }, | ||
| epochNanoseconds: { value: 0n }, | ||
| }); | ||
| strictEqual(isTemporalInstant(nativeLike), true); | ||
| }); | ||
|
|
||
| test("isTemporalInstant() rejects unrelated values", () => { | ||
| strictEqual(isTemporalInstant(null), false); | ||
| strictEqual(isTemporalInstant(undefined), false); | ||
| strictEqual(isTemporalInstant("2026-05-14T00:00:00Z"), false); | ||
| strictEqual(isTemporalInstant(new Date()), false); | ||
| strictEqual( | ||
| isTemporalInstant(Temporal.Duration.from({ seconds: 1 })), | ||
| false, | ||
| ); | ||
| }); | ||
|
|
||
| test("isTemporalInstant() rejects bare objects tagged but missing shape", () => { | ||
| const decoy = Object.create(null, { | ||
| [Symbol.toStringTag]: { value: "Temporal.Instant" }, | ||
| }); | ||
| strictEqual(isTemporalInstant(decoy), false); | ||
| }); | ||
|
|
||
| test("isTemporalDuration() accepts polyfill instances", () => { | ||
| strictEqual( | ||
| isTemporalDuration(Temporal.Duration.from({ hours: 1 })), | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| test("isTemporalDuration() accepts spec-compliant non-polyfill objects", () => { | ||
| const nativeLike = Object.create(null, { | ||
| [Symbol.toStringTag]: { value: "Temporal.Duration" }, | ||
| sign: { value: 0 }, | ||
| }); | ||
| strictEqual(isTemporalDuration(nativeLike), true); | ||
| }); | ||
|
|
||
| test("isTemporalDuration() rejects unrelated values", () => { | ||
| strictEqual(isTemporalDuration(null), false); | ||
| strictEqual(isTemporalDuration(undefined), false); | ||
| strictEqual(isTemporalDuration("PT1H"), false); | ||
| strictEqual( | ||
| isTemporalDuration(Temporal.Instant.from("2026-05-14T00:00:00Z")), | ||
| false, | ||
| ); | ||
| }); | ||
|
|
||
| test("isTemporalDuration() rejects bare objects tagged but missing shape", () => { | ||
| const decoy = Object.create(null, { | ||
| [Symbol.toStringTag]: { value: "Temporal.Duration" }, | ||
| }); | ||
| strictEqual(isTemporalDuration(decoy), false); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.