Skip to content

Commit f339903

Browse files
committed
chore: add types
1 parent b55261d commit f339903

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/date.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class _Date {
1818
* @param years
1919
* @param refDate
2020
*/
21-
past(years?: number, refDate?: string) {
21+
past(years?: number, refDate?: string): Date {
2222
let date = new Date();
2323
if (typeof refDate !== 'undefined') {
2424
date = new Date(Date.parse(refDate));
@@ -43,7 +43,7 @@ export class _Date {
4343
* @param years
4444
* @param refDate
4545
*/
46-
future(years?: number, refDate?: string) {
46+
future(years?: number, refDate?: string): Date {
4747
let date = new Date();
4848
if (typeof refDate !== 'undefined') {
4949
date = new Date(Date.parse(refDate));
@@ -68,7 +68,7 @@ export class _Date {
6868
* @param from
6969
* @param to
7070
*/
71-
between(from: string, to: string) {
71+
between(from: string, to: string): Date {
7272
const fromMilli = Date.parse(from);
7373
const dateOffset = this.faker.datatype.number(Date.parse(to) - fromMilli);
7474

@@ -83,16 +83,18 @@ export class _Date {
8383
* @method faker.date.between
8484
* @param from
8585
* @param to
86+
* @param num
8687
*/
87-
betweens(from, to, num) {
88+
betweens(from: string, to: string, num?: number): Date[] {
8889
if (typeof num == 'undefined') {
8990
num = 3;
9091
}
91-
const newDates = [];
92+
const newDates: Date[] = [];
9293
let fromMilli = Date.parse(from);
9394
const dateOffset = (Date.parse(to) - fromMilli) / (num + 1);
94-
let lastDate = from;
95+
let lastDate: string | Date = from;
9596
for (let i = 0; i < num; i++) {
97+
// TODO @Shinigami92 2022-01-11: It may be a bug that `lastDate` is passed to parse if it's a `Date` not a `string`
9698
fromMilli = Date.parse(lastDate);
9799
lastDate = new Date(fromMilli + dateOffset);
98100
newDates.push(lastDate);
@@ -107,7 +109,7 @@ export class _Date {
107109
* @param days
108110
* @param refDate
109111
*/
110-
recent(days, refDate) {
112+
recent(days?: number, refDate?: string): Date {
111113
let date = new Date();
112114
if (typeof refDate !== 'undefined') {
113115
date = new Date(Date.parse(refDate));
@@ -132,7 +134,7 @@ export class _Date {
132134
* @param days
133135
* @param refDate
134136
*/
135-
soon(days, refDate) {
137+
soon(days?: number, refDate?: string): Date {
136138
let date = new Date();
137139
if (typeof refDate !== 'undefined') {
138140
date = new Date(Date.parse(refDate));
@@ -156,7 +158,7 @@ export class _Date {
156158
* @method faker.date.month
157159
* @param options
158160
*/
159-
month(options) {
161+
month(options?: { abbr?: boolean; context?: boolean }) {
160162
options = options || {};
161163

162164
let type = 'wide';
@@ -182,7 +184,7 @@ export class _Date {
182184
* @method faker.date.weekday
183185
* @param options
184186
*/
185-
weekday(options) {
187+
weekday(options?: { abbr?: boolean; context?: boolean }) {
186188
options = options || {};
187189

188190
let type = 'wide';

0 commit comments

Comments
 (0)