Skip to content
This repository was archived by the owner on Oct 20, 2021. It is now read-only.

Commit 103e057

Browse files
fix(rules): Accept more input types to parse date
1 parent 8d77426 commit 103e057

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/rules/abstract-date.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as moment from 'moment';
22

33
import { AbstractRule } from './abstract-rule';
4-
import { IntVal } from './int-val';
4+
import { BooleanType } from './boolean-type';
5+
import { NumberVal } from './number-val';
56
import { StringType } from './string-type';
67

78
export abstract class AbstractDate extends AbstractRule {
@@ -19,7 +20,7 @@ export abstract class AbstractDate extends AbstractRule {
1920
public validate(input: any): boolean {
2021
const date: moment.Moment = this.parseDate(input);
2122

22-
return this.validateDate(date);
23+
return date.isValid() && this.validateDate(date);
2324
}
2425

2526
/**
@@ -31,16 +32,20 @@ export abstract class AbstractDate extends AbstractRule {
3132
* Parse Date.
3233
*/
3334
private parseDate(input: any): moment.Moment {
34-
if (new IntVal().validate(input)) {
35-
return moment([input]);
35+
if (new NumberVal().validate(input)) {
36+
if (moment([input]).isValid()) {
37+
return moment([input]);
38+
}
39+
40+
return moment.unix(Number(input));
3641
}
3742

3843
if (new StringType().validate(input)) {
3944
return moment(input, this.format);
4045
}
4146

42-
if (moment.isMoment(input)) {
43-
return input;
47+
if (new BooleanType().validate(input)) {
48+
return moment();
4449
}
4550

4651
return moment(input);

0 commit comments

Comments
 (0)