Skip to content

fix(fake-timers): convert Date to milliseconds before passing to @sinonjs/fake-timers#16029

Open
Gdhanush-13 wants to merge 1 commit intojestjs:mainfrom
Gdhanush-13:fix/set-system-time-date
Open

fix(fake-timers): convert Date to milliseconds before passing to @sinonjs/fake-timers#16029
Gdhanush-13 wants to merge 1 commit intojestjs:mainfrom
Gdhanush-13:fix/set-system-time-date

Conversation

@Gdhanush-13
Copy link
Copy Markdown

Summary

Fixes #16028

Problem

Since @sinonjs/fake-timers@15.3.0, clock.setSystemTime() only accepts milliseconds (number), throwing TypeError: now should be milliseconds since UNIX epoch when a Date object is passed.

Jest's setSystemTime() API accepts both number | Date, but forwards the value directly to @sinonjs/fake-timers without conversion.

Fix

Convert Date objects to milliseconds via .getTime() before passing to the underlying sinon clock in two places:

  1. setSystemTime() - the public API called by users
  2. _toSinonFakeTimersConfig() - where the now config option is passed during useFakeTimers()

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 3, 2026

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9d5084c
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/69cf8e96b03bf700089e63a6
😎 Deploy Preview https://deploy-preview-16029--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Apr 3, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Gdhanush-13 / name: Gdhanush_13 (9d5084c)

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 3, 2026

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@16029

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@16029

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@16029

create-jest

npm i https://pkg.pr.new/create-jest@16029

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@16029

expect

npm i https://pkg.pr.new/expect@16029

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@16029

jest

npm i https://pkg.pr.new/jest@16029

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@16029

jest-circus

npm i https://pkg.pr.new/jest-circus@16029

jest-cli

npm i https://pkg.pr.new/jest-cli@16029

jest-config

npm i https://pkg.pr.new/jest-config@16029

@jest/console

npm i https://pkg.pr.new/@jest/console@16029

@jest/core

npm i https://pkg.pr.new/@jest/core@16029

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@16029

jest-diff

npm i https://pkg.pr.new/jest-diff@16029

jest-docblock

npm i https://pkg.pr.new/jest-docblock@16029

jest-each

npm i https://pkg.pr.new/jest-each@16029

@jest/environment

npm i https://pkg.pr.new/@jest/environment@16029

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@16029

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@16029

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@16029

@jest/expect

npm i https://pkg.pr.new/@jest/expect@16029

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@16029

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@16029

@jest/globals

npm i https://pkg.pr.new/@jest/globals@16029

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@16029

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@16029

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@16029

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@16029

jest-message-util

npm i https://pkg.pr.new/jest-message-util@16029

jest-mock

npm i https://pkg.pr.new/jest-mock@16029

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@16029

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@16029

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@16029

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@16029

jest-resolve

npm i https://pkg.pr.new/jest-resolve@16029

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@16029

jest-runner

npm i https://pkg.pr.new/jest-runner@16029

jest-runtime

npm i https://pkg.pr.new/jest-runtime@16029

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@16029

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@16029

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@16029

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@16029

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@16029

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@16029

@jest/transform

npm i https://pkg.pr.new/@jest/transform@16029

@jest/types

npm i https://pkg.pr.new/@jest/types@16029

jest-util

npm i https://pkg.pr.new/jest-util@16029

jest-validate

npm i https://pkg.pr.new/jest-validate@16029

jest-watcher

npm i https://pkg.pr.new/jest-watcher@16029

jest-worker

npm i https://pkg.pr.new/jest-worker@16029

pretty-format

npm i https://pkg.pr.new/pretty-format@16029

commit: 9d5084c

…onjs/fake-timers

Since @sinonjs/fake-timers@15.3.0, setSystemTime() only accepts
milliseconds (number), not Date objects. Jest's setSystemTime() API
accepts both number and Date, so we need to convert Date to
milliseconds via .getTime() before forwarding to the underlying
clock.

Also fixes the same issue in _toSinonFakeTimersConfig() where
the config 'now' option (which can be a Date) is passed directly.

Closes jestjs#16028
@Gdhanush-13 Gdhanush-13 force-pushed the fix/set-system-time-date branch from d968be9 to 9d5084c Compare April 3, 2026 09:55
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.

[Bug]: setSystemTime doesn't accept Date

1 participant