Skip to content

Time of date is not seedable #3519

@dbartholomae

Description

@dbartholomae

Pre-Checks

Describe the bug

When creating a random date without a refDate and with a seed, the time of the date still changes randomly.

Minimal reproduction code

import { base, de, en, Faker } from "@faker-js/faker";

const faker1 = new Faker({ locale: [de, en, base], seed: 1 });
const faker2 = new Faker({ locale: [de, en, base], seed: 1 });

console.log(faker1.date.past());
setTimeout(() => console.log(faker2.date.past()), 1_000);
// Times of dates will be different by roughly one second

Additional Context

This is I think because past just gets the time from refDate which is set to now by default:

get defaultRefDate(): () => Date {

Environment Info

System:
    OS: macOS 15.4.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 10.81 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.15.0 - ~/.nvm/versions/node/v22.15.0/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v22.15.0/bin/npm
    pnpm: 10.8.1 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 136.0.7103.114

Which module system do you use?

  • CJS
  • ESM

Used Package Manager

pnpm

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions