Skip to content

Datetime

Random Date values for past, future, windows around “today”, explicit ranges, and birthdates.

future

Returns a date in the future by adding a random number of days. The day count is sampled in [minFutureYears * 365, maxFutureYears * 365) using integer semantics (see basic integer).

ts
dunna.datetime.future();
dunna.datetime.future({ minFutureYears: 1, maxFutureYears: 5 });
OptionTypeDescriptionDefault
minFutureYearsnumberLower bound on the year span used to build the day range1
maxFutureYearsnumberUpper bound on the year span used to build the day range10

past

Returns a date in the past by subtracting a random number of days, with day count sampled in [minPastYears * 365, maxPastYears * 365).

ts
dunna.datetime.past();
dunna.datetime.past({ minPastYears: 2, maxPastYears: 20 });
OptionTypeDescriptionDefault
minPastYearsnumberLower bound on the year span1
maxPastYearsnumberUpper bound on the year span10

near

Returns a date in the future by adding a random number of days in [minFutureDays, maxFutureDays) to today.

ts
dunna.datetime.near();
dunna.datetime.near({ minFutureDays: 1, maxFutureDays: 14 });
OptionTypeDescriptionDefault
minFutureDaysnumberMinimum days ahead1
maxFutureDaysnumberMaximum days ahead (exclusive upper bound for the integer draw)10

between

Returns a random date uniformly between two Date instances (inclusive of the range in time, via internal float sampling).

ts
dunna.datetime.between({
  min: new Date('2020-01-01'),
  max: new Date('2030-01-01'),
});
OptionTypeDescription
minDateStart of range
maxDateEnd of range

birthdate

Returns a random date between 1 January 1900 and 1 January 2025 (implementation-defined window).

ts
dunna.datetime.birthdate();