Skip to content

Commit 8fc5261

Browse files
authored
refactor(datatype): deprecate datetime (#2053)
1 parent a49aa0d commit 8fc5261

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

docs/guide/upgrading.md

+4
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ faker.number.float({ max: 100, precision: 0.01 }); // 35.21
274274
The method `faker.datatype.array` has been deprecated and will be removed in v9.
275275
If you need an array of useful values, you are better off creating your own one using `faker.helpers.multiple`.
276276

277+
### `faker.datatype.datetime` deprecated in favor of `faker.date.between`
278+
279+
The `datetime` method previously found in `faker.datatype` has been deprecated, use `faker.date.between` instead.
280+
277281
### `allowLeadingZeros` behavior change in `faker.string.numeric`
278282

279283
The `allowLeadingZeros` boolean parameter in `faker.string.numeric` (in the new `string` module) now defaults to `true`. `faker.string.numeric` will now generate numeric strings that could have leading zeros by default.

src/modules/datatype/index.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,16 @@ export class DatatypeModule {
166166
* When not provided or larger than `8640000000000000`, `2100-01-01` is considered
167167
* as maximum generated date. Defaults to `4102444800000`.
168168
*
169+
* @see faker.date.between()
170+
*
169171
* @example
170172
* faker.datatype.datetime() // '2089-04-17T18:03:24.956Z'
171173
* faker.datatype.datetime(1893456000000) // '2022-03-28T07:00:56.876Z'
172174
* faker.datatype.datetime({ min: 1577836800000, max: 1893456000000 }) // '2021-09-12T07:13:00.255Z'
173175
*
174176
* @since 5.5.0
177+
*
178+
* @deprecated Use `faker.date.between({ from: min, to: max })` instead.
175179
*/
176180
datetime(
177181
options:
@@ -195,6 +199,13 @@ export class DatatypeModule {
195199
max?: number;
196200
} = {}
197201
): Date {
202+
deprecated({
203+
deprecated: 'faker.datatype.datetime({ min, max })',
204+
proposed: 'faker.date.between({ from, to })',
205+
since: '8.0',
206+
until: '9.0',
207+
});
208+
198209
const minMax = 8640000000000000;
199210

200211
let min = typeof options === 'number' ? undefined : options.min;
@@ -208,7 +219,7 @@ export class DatatypeModule {
208219
max = Date.UTC(2100, 0);
209220
}
210221

211-
return new Date(this.faker.number.int({ min, max }));
222+
return this.faker.date.between({ from: min, to: max });
212223
}
213224

214225
/**

0 commit comments

Comments
 (0)