---
title: "A bug at a particular date or time: fake the clock | Proofline"
description: "Some reports come with a date attached: it broke on the last day of the month, on the night the clocks changed, on New Year's Eve, or an hour after login."
url: https://proofline.sh/learn/fake-clock-repro/
---

[Learning center](/learn/)

# A bug at a particular date or time: fake the clock

Some reports come with a date attached: it broke on the last day of the month, on the night the clocks changed, on New Year's Eve, or an hour after login. The maintainer cannot wait for that moment. Set the browser's clock to it instead, and move time forward under control.

Schema conflicts The Proofline team November 22, 2026 3 min read

## Capture the moment

From the reporter, record:

-   The time of the bug as an instant, in UTC: `2026-03-29T00:59:00Z`, not "around 2 am"
-   The browser's time zone: `Intl.DateTimeFormat().resolvedOptions().timeZone`
-   How long the page had been open, and whether the tab was in the background

The time zone matters as much as the instant. The same instant is a different calendar date and wall-clock time in different zones, and daylight saving transitions happen on different dates. [Replay the time zone and locale](/learn/replay-timezone-locale/) covers capturing it.

## Set the clock in Playwright

Playwright's clock API replaces `Date`, timers and related functions in the page:

```
const context = await browser.newContext({ timezoneId: 'Europe/Berlin' });
const page = await context.newPage();
await page.clock.install({ time: new Date('2026-03-29T00:59:00Z') });
await page.goto('https://staging.example.test/schedule');
await page.clock.fastForward('01:00:00'); // one hour later, firing due timers
```

[Playwright: Clock](https://playwright.dev/docs/clock)

We ran that in Chromium on a test page. Before the jump, `new Date().toString()` showed `01:59:00 GMT+0100 (Central European Standard Time)`. One hour later it showed `03:59:00 GMT+0200 (Central European Summer Time)`: the wall clock moved two hours, because Berlin's clocks went forward at 01:00 UTC that night. A one-hour timer set before the jump had fired. Code that adds 60 minutes to a displayed time, or assumes every day has 24 hours, fails here.

`page.clock.setFixedTime()` stops time at one instant, for bugs that depend on the date but not on timers. Setting `2026-12-31T23:59:59Z` with the context in `Europe/Berlin` made `new Date().getFullYear()` return 2027, since it was already the new year in Berlin.

## Choose the method for the bug

| The bug depends on | Use |
| --- | --- |
| The calendar date or time at page load | `clock.setFixedTime()` or `clock.install({ time })` |
| A timer or a timeout, such as session expiry after 30 minutes | `clock.install()` then `clock.fastForward()` or `clock.runFor()` |
| An animation or polling loop | `clock.install()` then `clock.runFor()` in small steps |
| The server's clock, such as a token's expiry checked by the API | Not the browser clock: the server must be in that state too |

The last row is the limit. Faking the browser's clock does not change the server's, so a bug in how the page and server disagree about time needs both sides set, or a response replayed with the times the reporter's server sent. [Replay recorded responses](/learn/har-replay-playwright/) covers the second.

## Moments worth testing

-   The last day of a month, and the 29th to 31st when code adds one month
-   Daylight saving changes in both directions in the users' zones
-   Midnight in the user's zone versus midnight UTC
-   The year boundary, and week numbering around it
-   Leap days
-   Session or token expiry, and the minute after it

## Worked example: a renewal date one month off

This example is fictional. On January 31, a tester reports that the subscription page shows the next renewal as March 3. The developer looks the next day and sees March 1.

The developer fixes the clock with `setFixedTime(new Date('2027-01-31T10:00:00Z'))` and sees March 3 on every run. The page computed next month with `date.setMonth(date.getMonth() + 1)`, which turns January 31 into "February 31", rolled over to March 3. The test with the fixed date became a regression test, and the fix clamped the day to the end of the target month.

## Questions

### Does faking the clock affect `performance.now()`?

Playwright's clock also controls `performance.now()`. A page that measures elapsed time sees the faked time.

### Can I fake the clock without Playwright?

Test frameworks such as Jest and Vitest have fake timers for unit tests. In DevTools, there is no clock override, but you can set the OS clock in a virtual machine.

### The bug depends on the tab being in the background for an hour. Does fast-forwarding cover that?

It covers the timers. Background tabs also have their timers throttled by the browser, which the clock API does not simulate. If the bug depends on throttling, reproduce it in a real background tab and say so.

Return to [reproducing what someone else saw](/learn/replay-browser-bug-report/) for the other layers a replay needs.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Replay the reporter's time zone and locale](/learn/replay-timezone-locale/)
    
    Schema conflicts The Proofline team November 22, 2026 3 min read
    
-   ### [A date shows one day off: find where the value shifted](/learn/date-off-by-one-timezone/)
    
    Schema conflicts The Proofline team November 20, 2026 5 min read
