Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for quickrange to use datemath to parse datetime strings #65

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/plugins/data/common/data_frames/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { IFieldType } from './fields';
import { IndexPatternFieldMap, IndexPatternSpec } from '../index_patterns';
import { IOpenSearchDashboardsSearchRequest } from '../search';
import { GetAggTypeFn, GetDataFrameAggQsFn } from '../types';
import { GetAggTypeFn, GetDataFrameAggQsFn, TimeRange } from '../types';

/**
* Returns the raw data frame from the search request.
Expand Down Expand Up @@ -290,6 +290,26 @@ export const getTimeField = (
: fields.find((field) => field.type === 'date');
};

/**
* Parses timepicker datetimes using datemath package. Will attempt to parse strings such as
* "now - 15m"
*
* @param dateRange - of type TimeRange
* @returns object with fromDate and toDate, both of which will be in utc time and formatted to
* 'YYYY-MM-DD HH:mm:ss.SSS'
*/
export const formatTimePickerDate = (dateRange: TimeRange) => {
const dateMathParse = (date: string) => {
const parsedDate = datemath.parse(date);
return parsedDate ? parsedDate.utc().format('YYYY-MM-DD HH:mm:ss.SSS') : '';
};

const fromDate = dateMathParse(dateRange.from);
const toDate = dateMathParse(dateRange.to);

return { fromDate, toDate };
};

/**
* Checks if the value is a GeoPoint. Expects an object with lat and lon properties.
*
Expand Down
Loading