Skip to content

Commit af6f3c2

Browse files
committed
fix: Respect timezone for natural language date parsing and align custom date ranges to dates by default to ensure backward compatibility
1 parent 2104492 commit af6f3c2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* globals describe,test,expect */
2+
3+
const dateParser = require('./dateParser');
4+
5+
describe(`dateParser`, () => {
6+
test(`custom daily ranges returns day aligned dateRange`, () => {
7+
expect(dateParser('from 1 days ago to now', 'UTC')).toStrictEqual(
8+
[dateParser('yesterday', 'UTC')[0], dateParser('today', 'UTC')[1]]
9+
);
10+
});
11+
12+
test(`last 6 hours`, () => {
13+
expect(dateParser('last 6 hours', 'UTC')).toStrictEqual(
14+
[
15+
new Date((Math.floor(new Date().getTime() / (1000 * 60 * 60)) - 7) * (1000 * 60 * 60)).toISOString().replace('Z', ''),
16+
new Date((Math.floor(new Date().getTime() / (1000 * 60 * 60))) * (1000 * 60 * 60) - 1).toISOString().replace('Z', '')
17+
]
18+
);
19+
});
20+
});

0 commit comments

Comments
 (0)