Restore Date object support broken by PR #556#561
Merged
fatso83 merged 1 commit intosinonjs:mainfrom Apr 10, 2026
Merged
Conversation
The change from `typeof epoch.getTime === "function"` to `instanceof Date` in #556 broke cross-realm Date support. When Jest runs tests in a different realm/context, Date objects created there fail the `instanceof Date` check because each realm has its own Date constructor. This restores the original duck-typing approach that works across realms. Fixes the error: "TypeError: now should be milliseconds since UNIX epoch"
fatso83
added a commit
that referenced
this pull request
Apr 10, 2026
Contributor
|
added the missing regression test in aa15fde for you, as I introduced the regression 😉 |
Contributor
|
Unfortunately, this fix was incomplete, as the typing now breaks. This is what I get for not ensuring the types are built as part of the github actions. At least I know that now 😄 I'll get it fixed. |
Contributor
|
types are now always built and the type regression fixed in d43b719 release 15.3.1 out in a few jiffies |
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.
Purpose (TL;DR) - mandatory
Fix cross-realm Date regression introduced in #556.
Background (Problem in detail)
The public API accepts
Date | number, but the change in #556 fromtypeof epoch.getTime === "function"toinstanceof Datebroke support for Date objects from different realms (iframes, vm contexts, etc.), sinceinstanceoffails across realms.Error:
TypeError: now should be milliseconds since UNIX epochReproduction:
Solution
Restore the original duck-typing approach
(typeof epoch.getTime === "function")that worked before #556.