Skip to content

Commit 385c03a

Browse files
authored
chore: add examples and improve jsdocs for datatype.datetime (#907)
1 parent a1685e1 commit 385c03a

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/datatype.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,24 @@ export class Datatype {
100100
* Returns a Date object using a random number of milliseconds since
101101
* the [Unix Epoch](https://en.wikipedia.org/wiki/Unix_time) (1 January 1970 UTC).
102102
*
103-
* @param options Max number of milliseconds since unix epoch or options object
103+
* @param options Max number of milliseconds since unix epoch or options object.
104104
* @param options.min Lower bound for milliseconds since base date.
105105
* When not provided or smaller than `-8640000000000000`, `1990-01-01` is considered
106-
* as minimum generated date. Defaults to `633880849813`.
106+
* as minimum generated date. Defaults to `631152000000`.
107107
* @param options.max Upper bound for milliseconds since base date.
108108
* When not provided or larger than `8640000000000000`, `2100-01-01` is considered
109-
* as maximum generated date.
109+
* as maximum generated date. Defaults to `4102444800000`.
110+
*
111+
* @example
112+
* faker.datatype.datetime() // '2089-04-17T18:03:24.956Z'
113+
* faker.datatype.datetime(1893456000000) // '2022-03-28T07:00:56.876Z'
114+
* faker.datatype.datetime({ min: 1577836800000, max: 1893456000000 }) // '2021-09-12T07:13:00.255Z'
110115
*/
111-
datetime(options?: number | { min?: number; max?: number }): Date {
116+
datetime(options: number | { min?: number; max?: number } = {}): Date {
112117
const minMax = 8640000000000000;
113118

114-
let min = typeof options === 'number' ? undefined : options?.min;
115-
let max = typeof options === 'number' ? options : options?.max;
119+
let min = typeof options === 'number' ? undefined : options.min;
120+
let max = typeof options === 'number' ? options : options.max;
116121

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

0 commit comments

Comments
 (0)