interface-forge - v2.5.0
    Preparing search index...

    Class SimpleDateModule

    Module to generate dates (without methods requiring localized data).

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Methods

    • Generates a random date that can be either in the past or in the future.

      Parameters

      • Optionaloptions: { refDate?: string | number | Date }

        The optional options object.

        • OptionalrefDate?: string | number | Date

          The date to use as reference point for the newly generated date.

          faker.defaultRefDate()
          

      Returns Date

      • faker.date.between(): For generating dates in a specific range.
      • faker.date.past(): For generating dates explicitly in the past.
      • faker.date.future(): For generating dates explicitly in the future.
      faker.date.anytime() // '2022-07-31T01:33:29.567Z'
      

      8.0.0

    • Generates a random date between the given boundaries.

      Parameters

      • options: { from: string | number | Date; to: string | number | Date }

        The options object.

        • from: string | number | Date

          The early date boundary.

        • to: string | number | Date

          The late date boundary.

      Returns Date

      If from or to are not provided.

      If from is after to.

      faker.date.between({ from: '2020-01-01T00:00:00.000Z', to: '2030-01-01T00:00:00.000Z' }) // '2026-05-16T02:22:53.002Z'
      

      8.0.0

    • Generates random dates between the given boundaries. The dates will be returned in an array sorted in chronological order.

      Parameters

      • options: {
            count?: number | { max: number; min: number };
            from: string | number | Date;
            to: string | number | Date;
        }

        The options object.

        • Optionalcount?: number | { max: number; min: number }

          The number of dates to generate.

          3
          
        • from: string | number | Date

          The early date boundary.

        • to: string | number | Date

          The late date boundary.

      Returns Date[]

      If from or to are not provided.

      If from is after to.

      faker.date.betweens({ from: '2020-01-01T00:00:00.000Z', to: '2030-01-01T00:00:00.000Z' })
      // [
      // '2022-07-02T06:00:00.000Z',
      // '2024-12-31T12:00:00.000Z',
      // '2027-07-02T18:00:00.000Z'
      // ]
      faker.date.betweens({ from: '2020-01-01T00:00:00.000Z', to: '2030-01-01T00:00:00.000Z', count: 2 })
      // [ '2023-05-02T16:00:00.000Z', '2026-09-01T08:00:00.000Z' ]
      faker.date.betweens({ from: '2020-01-01T00:00:00.000Z', to: '2030-01-01T00:00:00.000Z', count: { min: 2, max: 5 }})
      // [
      // 2021-12-19T06:35:40.191Z,
      // 2022-09-10T08:03:51.351Z,
      // 2023-04-19T11:41:17.501Z
      // ]

      8.0.0

    • Returns a random birthdate. By default, the birthdate is generated for an adult between 18 and 80 years old. But you can customize the 'age' range or the 'year' range to generate a more specific birthdate.

      Parameters

      • Optionaloptions: { refDate?: string | number | Date }

        The options to use to generate the birthdate.

        • OptionalrefDate?: string | number | Date

          The date to use as reference point for the newly generated date.

          faker.defaultRefDate()
          

      Returns Date

      faker.date.birthdate() // '1977-07-10T01:37:30.719Z'
      

      7.0.0

    • Returns a random birthdate for a given age range.

      Parameters

      • options: { max: number; min: number; mode: "age"; refDate?: string | number | Date }

        The options to use to generate the birthdate.

        • max: number

          The maximum age to generate a birthdate for.

        • min: number

          The minimum age to generate a birthdate for.

        • mode: "age"

          'age' to generate a birthdate based on the age range. It is also possible to generate a birthdate based on a 'year' range.

        • OptionalrefDate?: string | number | Date

          The date to use as reference point for the newly generated date.

          faker.defaultRefDate()
          

      Returns Date

      faker.date.birthdate({ mode: 'age', min: 18, max: 65 }) // '2003-11-02T20:03:20.116Z'
      

      7.0.0

    • Returns a random birthdate in the given range of years.

      Parameters

      • options: { max: number; min: number; mode: "year" }

        The options to use to generate the birthdate.

        • max: number

          The maximum year to generate a birthdate in.

        • min: number

          The minimum year to generate a birthdate in.

        • mode: "year"

          'year' to generate a birthdate based on the year range. It is also possible to generate a birthdate based on an 'age' range.

      Returns Date

      faker.date.birthdate({ mode: 'year', min: 1900, max: 2000 }) // '1940-08-20T08:53:07.538Z'
      

      7.0.0

    • Returns a random birthdate. By default, the birthdate is generated for an adult between 18 and 80 years old. But you can customize the 'age' range or the 'year' range to generate a more specific birthdate.

      Parameters

      • Optionaloptions:
            | { refDate?: string
            | number
            | Date }
            | {
                max: number;
                min: number;
                mode: "age" | "year";
                refDate?: string | number | Date;
            }

        The options to use to generate the birthdate.

        • { refDate?: string | number | Date }
          • OptionalrefDate?: string | number | Date

            The date to use as reference point for the newly generated date.

            faker.defaultRefDate()
            
        • {
              max: number;
              min: number;
              mode: "age" | "year";
              refDate?: string | number | Date;
          }
          • max: number

            The maximum age/year to generate a birthdate for/in.

          • min: number

            The minimum age/year to generate a birthdate for/in.

          • mode: "age" | "year"

            Either 'age' or 'year' to generate a birthdate based on the age or year range.

          • OptionalrefDate?: string | number | Date

            The date to use as reference point for the newly generated date. Only used when mode is 'age'.

            faker.defaultRefDate()
            

      Returns Date

      faker.date.birthdate() // '1977-07-10T01:37:30.719Z'
      faker.date.birthdate({ mode: 'age', min: 18, max: 65 }) // '2003-11-02T20:03:20.116Z'
      faker.date.birthdate({ mode: 'year', min: 1900, max: 2000 }) // '1940-08-20T08:53:07.538Z'

      7.0.0

    • Generates a random date in the future.

      Parameters

      • Optionaloptions: { refDate?: string | number | Date; years?: number }

        The optional options object.

        • OptionalrefDate?: string | number | Date

          The date to use as reference point for the newly generated date.

          faker.defaultRefDate()
          
        • Optionalyears?: number

          The range of years the date may be in the future.

          1
          

      Returns Date

      faker.date.soon(): For generating dates in the near future (days instead of years).

      faker.date.future() // '2022-11-19T05:52:49.100Z'
      faker.date.future({ years: 10 }) // '2030-11-23T09:38:28.710Z'
      faker.date.future({ years: 10, refDate: '2020-01-01T00:00:00.000Z' }) // '2020-12-13T22:45:10.252Z'

      8.0.0

    • Generates a random date in the past.

      Parameters

      • Optionaloptions: { refDate?: string | number | Date; years?: number }

        The optional options object.

        • OptionalrefDate?: string | number | Date

          The date to use as reference point for the newly generated date.

          faker.defaultRefDate()
          
        • Optionalyears?: number

          The range of years the date may be in the past.

          1
          

      Returns Date

      faker.date.recent(): For generating dates in the recent past (days instead of years).

      faker.date.past() // '2021-12-03T05:40:44.408Z'
      faker.date.past({ years: 10 }) // '2017-10-25T21:34:19.488Z'
      faker.date.past({ years: 10, refDate: '2020-01-01T00:00:00.000Z' }) // '2017-08-18T02:59:12.350Z'

      8.0.0

    • Generates a random date in the recent past.

      Parameters

      • Optionaloptions: { days?: number; refDate?: string | number | Date }

        The optional options object.

        • Optionaldays?: number

          The range of days the date may be in the past.

          1
          
        • OptionalrefDate?: string | number | Date

          The date to use as reference point for the newly generated date.

          faker.defaultRefDate()
          

      Returns Date

      faker.date.past(): For generating dates further back in time (years instead of days).

      faker.date.recent() // '2022-02-04T02:09:35.077Z'
      faker.date.recent({ days: 10 }) // '2022-01-29T06:12:12.829Z'
      faker.date.recent({ days: 10, refDate: '2020-01-01T00:00:00.000Z' }) // '2019-12-27T18:11:19.117Z'

      8.0.0

    • Generates a random date in the near future.

      Parameters

      • Optionaloptions: { days?: number; refDate?: string | number | Date }

        The optional options object.

        • Optionaldays?: number

          The range of days the date may be in the future.

          1
          
        • OptionalrefDate?: string | number | Date

          The date to use as reference point for the newly generated date.

          faker.defaultRefDate()
          

      Returns Date

      faker.date.future(): For generating dates further in the future (years instead of days).

      faker.date.soon() // '2022-02-05T09:55:39.216Z'
      faker.date.soon({ days: 10 }) // '2022-02-11T05:14:39.138Z'
      faker.date.soon({ days: 10, refDate: '2020-01-01T00:00:00.000Z' }) // '2020-01-01T02:40:44.990Z'

      8.0.0