// Any Playwright test page that uses the current date normally leads to changes in the test results and hence failing tests.
// With this script and other files in `e2e/fixtures` we address this by fixing the `now` date to a hardcoded value.
//
// The solution is inspired by:
// * GitHub issue and comment: https://github.com/microsoft/playwright/issues/6347#issuecomment-1085850728
//   where we can set the date for the test pages.
// * GitHub issue and comment: https://github.com/microsoft/playwright/issues/6347#issuecomment-1884463948
//   where we extend the test fixtures to set the date for the test pages.

// Pick the new/fake 'now' for the test pages.
const fakeNow = new Date('November 25 2000 13:37:11').valueOf()

// Extend Date constructor to default to fakeNow
// eslint-disable-next-line no-global-assign
Date = class extends Date {
  constructor(...args) {
    if (args.length === 0) {
      super(fakeNow)
    } else {
      super(...args)
    }
  }
}

// Override Date.now() to start from fakeNow
const __DateNowOffset = fakeNow - Date.now()
const __DateNow = Date.now
Date.now = () => __DateNow() + __DateNowOffset
