Skip to content

Commit

Permalink
Add support for date-only ISO strings closes #116
Browse files Browse the repository at this point in the history
  • Loading branch information
lroal committed Nov 19, 2024
1 parent 7c5941d commit d996b6f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/table/column/date/tryParseISO.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
var pattern = /(\d{4}-[01]\d-[0-3]\d(T| )[0-2]\d:[0-5]\d:[0-5]\d\.\d+)|(\d{4}-[01]\d-[0-3]\d(T| )[0-2]\d:[0-5]\d:[0-5]\d)|(\d{4}-[01]\d-[0-3]\d(T| )[0-2]\d:[0-5]\d)/;
var patternWithTime = /(\d{4}-[01]\d-[0-3]\d(T| )[0-2]\d:[0-5]\d:[0-5]\d\.\d+)|(\d{4}-[01]\d-[0-3]\d(T| )[0-2]\d:[0-5]\d:[0-5]\d)|(\d{4}-[01]\d-[0-3]\d(T| )[0-2]\d:[0-5]\d)/;
var patternDateOnly = /^\d{4}-[01]\d-[0-3]\d$/;

function tryParseISO(iso) {
if (pattern.test(iso))
if (patternWithTime.test(iso) || patternDateOnly.test(iso)) {
return iso;
else
throw new TypeError(iso + ' is not a valid Date');




} else {
throw new TypeError(iso + ' is not a valid Date');
}
}

module.exports = tryParseISO;

0 comments on commit d996b6f

Please sign in to comment.