-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Uptime] Update relative time handling (#55693)
* update relative time handling * fix type * update logic to handle end date * fix test * PR feedback * refactor code * refactor interval time * fix tests Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
1c705d8
commit 49e9c79
Showing
6 changed files
with
55 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
x-pack/legacy/plugins/uptime/server/lib/helper/__test__/parse_relative_date.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { parseRelativeDate } from '../get_histogram_interval'; | ||
import { Moment } from 'moment'; | ||
|
||
describe('Parsing a relative end date properly', () => { | ||
it('converts the upper range of relative end dates to now', async () => { | ||
const thisWeekEndDate = 'now/w'; | ||
|
||
let endDate = parseRelativeDate(thisWeekEndDate, { roundUp: true }); | ||
expect(Date.now() - (endDate as Moment).valueOf()).toBeLessThan(1000); | ||
|
||
const todayEndDate = 'now/d'; | ||
|
||
endDate = parseRelativeDate(todayEndDate, { roundUp: true }); | ||
|
||
expect(Date.now() - (endDate as Moment).valueOf()).toBeLessThan(1000); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters