Skip to content

Commit

Permalink
fix: accept negative timezone in isDateString (#564)
Browse files Browse the repository at this point in the history
Close #565
  • Loading branch information
alencarandre committed Mar 26, 2020
1 parent 84680ad commit 2012d72
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/validation/Validator.ts
Expand Up @@ -402,7 +402,7 @@ export class Validator {
* Checks if a given value is a ISOString date.
*/
isDateString(value: unknown): boolean {
const regex = /^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|\+[0-2]\d(?:\:[0-5]\d)?)?$/g;
const regex = /^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[\+\-][0-2]\d(?:\:[0-5]\d)?)?$/g;
return this.isString(value) && regex.test(value);
}

Expand Down
2 changes: 2 additions & 0 deletions test/functional/validation-functions-and-decorators.spec.ts
Expand Up @@ -729,6 +729,8 @@ describe("IsDateString", function() {
"2018-01-04T08:15:30Z",
"2018-01-04T08:15:30+04:00",
"2018-01-04T08:15:30+04",
"2020-03-26T11:00:01-03:00",
"2020-03-26T11:00:01-03",
];
const invalidValues = [
true,
Expand Down

0 comments on commit 2012d72

Please sign in to comment.