Skip to content

Commit

Permalink
chore: add types
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Jan 11, 2022
1 parent f0fb294 commit fd942ca
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class _Date {
* @param years
* @param refDate
*/
past(years?: number, refDate?: string) {
past(years?: number, refDate?: string): Date {
let date = new Date();
if (typeof refDate !== 'undefined') {
date = new Date(Date.parse(refDate));
Expand All @@ -43,7 +43,7 @@ export class _Date {
* @param years
* @param refDate
*/
future(years?: number, refDate?: string) {
future(years?: number, refDate?: string): Date {
let date = new Date();
if (typeof refDate !== 'undefined') {
date = new Date(Date.parse(refDate));
Expand All @@ -68,7 +68,7 @@ export class _Date {
* @param from
* @param to
*/
between(from: string, to: string) {
between(from: string, to: string): Date {
const fromMilli = Date.parse(from);
const dateOffset = this.faker.datatype.number(Date.parse(to) - fromMilli);

Expand All @@ -83,16 +83,18 @@ export class _Date {
* @method faker.date.between
* @param from
* @param to
* @param num
*/
betweens(from, to, num) {
betweens(from: string, to: string, num?: number): Date[] {
if (typeof num == 'undefined') {
num = 3;
}
const newDates = [];
const newDates: Date[] = [];
let fromMilli = Date.parse(from);
const dateOffset = (Date.parse(to) - fromMilli) / (num + 1);
let lastDate = from;
let lastDate: string | Date = from;
for (let i = 0; i < num; i++) {
// TODO @Shinigami92 2022-01-11: It may be a bug that `lastDate` is passed to parse if it's a `Date` not a `string`
fromMilli = Date.parse(lastDate);
lastDate = new Date(fromMilli + dateOffset);
newDates.push(lastDate);
Expand All @@ -107,7 +109,7 @@ export class _Date {
* @param days
* @param refDate
*/
recent(days, refDate) {
recent(days?: number, refDate?: string): Date {
let date = new Date();
if (typeof refDate !== 'undefined') {
date = new Date(Date.parse(refDate));
Expand All @@ -132,7 +134,7 @@ export class _Date {
* @param days
* @param refDate
*/
soon(days, refDate) {
soon(days?: number, refDate?: string): Date {
let date = new Date();
if (typeof refDate !== 'undefined') {
date = new Date(Date.parse(refDate));
Expand All @@ -156,7 +158,7 @@ export class _Date {
* @method faker.date.month
* @param options
*/
month(options) {
month(options?: { abbr?: boolean; context?: boolean }) {
options = options || {};

let type = 'wide';
Expand All @@ -182,7 +184,7 @@ export class _Date {
* @method faker.date.weekday
* @param options
*/
weekday(options) {
weekday(options?: { abbr?: boolean; context?: boolean }) {
options = options || {};

let type = 'wide';
Expand Down

0 comments on commit fd942ca

Please sign in to comment.