Skip to content

Commit 2cfecf5

Browse files
committed
fix dateParser + tests
1 parent 3b03974 commit 2cfecf5

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ export function dateParser(dateString, timezone, now = new Date()) {
8787

8888
momentRange = [momentRange[0].startOf(exactGranularity), momentRange[1].endOf(exactGranularity)];
8989
} else {
90-
const results = parse(dateString, new Date(moment().tz(timezone).format(moment.HTML5_FMT.DATETIME_LOCAL_MS)));
90+
const current = moment(now).tz(timezone);
91+
const results = parse(dateString, new Date(current.format(moment.HTML5_FMT.DATETIME_LOCAL_MS)));
92+
9193
if (!results?.length) {
9294
throw new UserError(`Can't parse date: '${dateString}'`);
9395
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ describe('dateParser', () => {
181181
);
182182
});
183183

184-
test('from 12AM till now by 1 hour', () => {
184+
test('from 12AM till now by hour', () => {
185185
Date.now = jest.fn().mockReturnValue(new Date(2021, 2, 5, 13, 0, 0, 0));
186-
expect(dateParser('from 12AM till now by 1 hour', 'UTC', new Date(2021, 2, 5, 13, 0, 0, 0))).toStrictEqual(
186+
expect(dateParser('2 weeks ago by hour', 'UTC', new Date(Date.UTC(2021, 2, 5, 13, 0, 0, 0)))).toStrictEqual(
187187
[
188-
'2021-03-05T00:00:00.000',
189-
'2021-03-05T11:59:59.999'
188+
'2021-02-19T13:00:00.000',
189+
'2021-02-19T13:59:59.999'
190190
]
191191
);
192192

0 commit comments

Comments
 (0)