Date
Module to generate dates.Overview
To quickly generate a date in the past, use recent() (last day) or past() (last year). To quickly generate a date in the future, use soon() (next day) or future() (next year). For a realistic birthdate for an adult, use birthdate().For more control, any of these methods can be customized with further options, or use between() to generate a single date between two dates, or betweens() for multiple dates.You can generate random localized month and weekday names using month()
and weekday()
.
anytime#
Generates a random date that can be either in the past or in the future.Name | Type | Default | Description |
---|
refDate | string | number | Date | {{$date.now}} | The date to use as reference point for the newly generated date. |
between#
Generates a random date between the given boundaries.Name | Type | Default | Description |
---|
from | string | number | Date | | The early date boundary. |
to | string | number | Date | | The late date boundary. |
betweens#
Generates random dates between the given boundaries. The dates will be returned in an array sorted in chronological order.Name | Type | Default | Description |
---|
count | number | { min: number; max: number; } | 3 | The number of dates to generate. |
from | string | number | Date | | The early date boundary. |
to | string | number | Date | | The late date boundary. |
birthdate#
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.Name | Type | Default | Description |
---|
refDate | string | number | Date | {{$date.now}} | The date to use as reference point for the newly generated 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. |
refDate | string | number| Date | {{$date.now}} | The date to use as reference point for the newly generated date. Only used when mode is 'age' . |
future#
Generates a random date in the future.Name | Type | Default | Description |
---|
refDate | string | number | Date | {{$date.now}} | The date to use as reference point for the newly generated date. |
years | number | 1 | The range of years the date may be in the future. |
month#
Returns a random name of a month.Name | Type | Default | Description |
---|
abbreviated | boolean | false | Whether to return an abbreviation. |
context | boolean | false | Whether to return the name of a month in the context of a date. In the default en locale this has no effect, however, in other locales like fr or ru , this may affect grammar or capitalization, for example 'январь' with { context: false } and 'января' with { context: true } in ru . |
past#
Generates a random date in the past.Name | Type | Default | Description |
---|
refDate | string | number | Date | {{$date.now}} | The date to use as reference point for the newly generated date. |
years | number | 1 | The range of years the date may be in the past. |
recent#
Generates a random date in the recent past.Name | Type | Default | Description |
---|
days | number | 1 | The range of days the date may be in the past. |
refDate | string | number | Date | {{$date.now}} | The date to use as reference point for the newly generated date. |
soon#
Generates a random date in the near future.Name | Type | Default | Description |
---|
days | number | 1 | The range of days the date may be in the future. |
refDate | string | number | Date | {{$date.now}} | The date to use as reference point for the newly generated date. |
timeZone#
Returns a random IANA time zone name.The returned time zone is not tied to the current locale.
weekday#
Returns a random day of the week.Name | Type | Default | Description |
---|
abbreviated | boolean | false | Whether to return an abbreviation. |
context | boolean | false | Whether to return the day of the week in the context of a date. In the default en locale this has no effect, however, in other locales like fr or ru , this may affect grammar or capitalization, for example 'Lundi' with { context: false } and 'lundi' with { context: true } in fr . |
Modified at 2024-09-02 09:29:22