67e28ac8b4
resolves https://github.com/elastic/kibana/issues/57446 Adds a new API (AlertClient and HTTP endpoint) `getAlertStatus()` which returns alert data calculated from the event log.
27 lines
848 B
TypeScript
27 lines
848 B
TypeScript
/*
|
|
* 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 { parseDuration } from '../../common/parse_duration';
|
|
|
|
/**
|
|
* Parse an ISO date or NNx duration string as a Date
|
|
*
|
|
* @param dateString an ISO date or NNx "duration" string representing now-duration
|
|
* @returns a Date or undefined if the dateString was not valid
|
|
*/
|
|
export function parseIsoOrRelativeDate(dateString: string): Date | undefined {
|
|
const epochMillis = Date.parse(dateString);
|
|
if (!isNaN(epochMillis)) return new Date(epochMillis);
|
|
|
|
let millis: number;
|
|
try {
|
|
millis = parseDuration(dateString);
|
|
} catch (err) {
|
|
return;
|
|
}
|
|
|
|
return new Date(Date.now() - millis);
|
|
}
|