Skip to content

Commit 1cfc7db

Browse files
committed
simplify regexp in dateParser
1 parent db45d38 commit 1cfc7db

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/cubejs-api-gateway/src/dateParser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ export function dateParser(dateString, timezone, now = new Date()) {
6565
moment.tz(timezone).endOf('day').add(1, 'day')
6666
];
6767
} else if (dateString.match(/^from (.*) to (.*)$/)) {
68-
const [, from, to] = dateString.match(/^from\s{1,3}(.{0,50})\s{1,3}to\s{1,3}(.{0,50})$/);
68+
const [, from, to] = dateString.match(/^from(.{0,50})to(.{0,50})$/);
6969

7070
const current = moment(now).tz(timezone);
71-
const fromResults = parse(from, new Date(current.format(moment.HTML5_FMT.DATETIME_LOCAL_MS)));
72-
const toResults = parse(to, new Date(current.format(moment.HTML5_FMT.DATETIME_LOCAL_MS)));
71+
const fromResults = parse(from.trim(), new Date(current.format(moment.HTML5_FMT.DATETIME_LOCAL_MS)));
72+
const toResults = parse(to.trim(), new Date(current.format(moment.HTML5_FMT.DATETIME_LOCAL_MS)));
7373

7474
if (!Array.isArray(fromResults) || !fromResults.length) {
7575
throw new UserError(`Can't parse date: '${from}'`);

0 commit comments

Comments
 (0)