Skip to content

Commit

Permalink
chore: add examples and improve jsdocs for datatype.datetime (#907)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored May 3, 2022
1 parent a1685e1 commit 385c03a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/datatype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,24 @@ export class Datatype {
* Returns a Date object using a random number of milliseconds since
* the [Unix Epoch](https://en.wikipedia.org/wiki/Unix_time) (1 January 1970 UTC).
*
* @param options Max number of milliseconds since unix epoch or options object
* @param options Max number of milliseconds since unix epoch or options object.
* @param options.min Lower bound for milliseconds since base date.
* When not provided or smaller than `-8640000000000000`, `1990-01-01` is considered
* as minimum generated date. Defaults to `633880849813`.
* as minimum generated date. Defaults to `631152000000`.
* @param options.max Upper bound for milliseconds since base date.
* When not provided or larger than `8640000000000000`, `2100-01-01` is considered
* as maximum generated date.
* as maximum generated date. Defaults to `4102444800000`.
*
* @example
* faker.datatype.datetime() // '2089-04-17T18:03:24.956Z'
* faker.datatype.datetime(1893456000000) // '2022-03-28T07:00:56.876Z'
* faker.datatype.datetime({ min: 1577836800000, max: 1893456000000 }) // '2021-09-12T07:13:00.255Z'
*/
datetime(options?: number | { min?: number; max?: number }): Date {
datetime(options: number | { min?: number; max?: number } = {}): Date {
const minMax = 8640000000000000;

let min = typeof options === 'number' ? undefined : options?.min;
let max = typeof options === 'number' ? options : options?.max;
let min = typeof options === 'number' ? undefined : options.min;
let max = typeof options === 'number' ? options : options.max;

if (min == null || min < minMax * -1) {
min = Date.UTC(1990, 0);
Expand Down

0 comments on commit 385c03a

Please sign in to comment.