Skip to content

faker.time module to simplify time (not datetime) usecases #3107

Open
@douglasg14b

Description

@douglasg14b

Clear and concise description of the problem

Generating fakes specifically for times, not necessarily dates. These will only produce times, and not consider dates.

The date fucntions do perform this utility to some degree but require additional work to achieve which could be baked into a time module directly.

Suggested solution

in module faker.date or in a new module faker.time it would have fucntions for:

  • faker.time.between
  • faker.time.after
  • faker.time.range
  • ....etc

These should accept a format argument that allows the time output to be formatted as 24/12h time (or others)

Alternative

Users build their own time fucntions that work on top of faker.date

Additional context

Naive examples from my own use:

function getFakeTime(options?: { from?: Date; to?: Date } = {}) {
    const from = options?.from || '2024-01-01T00:00:00.000Z';
    const to = options?.to || '2024-01-01T23:59:59.999Z';

    return faker.date.between({from, to});
}

function getFake24hTime(time?: Date) {
    const dateTime = time || getFakeTime();
    return dateTime.toISOString().slice(11, 16);
}

function getFake24hTimeRange() {
    const from = getFakeTime();
    const to = getFakeTime({from});
    return {
        from: getFake24hTime(from),
        to: getFake24hTime(to),
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions