本文整理匯總了TypeScript中@elastic/datemath.parse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript parse函數的具體用法?TypeScript parse怎麽用?TypeScript parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了parse函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: setLoading
(async () => {
setLoading(true);
try {
const from = DateMath.parse(timerange.from);
const to = DateMath.parse(timerange.to, { roundUp: true });
if (!from || !to) {
throw new Error('Unalble to parse timerange');
}
const response = await fetch.post<MetricsExplorerResponse>(
'../api/infra/metrics_explorer',
{
metrics:
options.aggregation === MetricsExplorerAggregation.count
? [{ aggregation: MetricsExplorerAggregation.count }]
: options.metrics.map(metric => ({
aggregation: metric.aggregation,
field: metric.field,
})),
groupBy: options.groupBy,
afterKey,
limit: options.limit,
indexPattern: source.metricAlias,
filterQuery:
(options.filterQuery &&
convertKueryToElasticSearchQuery(options.filterQuery, derivedIndexPattern)) ||
void 0,
timerange: {
...timerange,
field: source.fields.timestamp,
from: from.valueOf(),
to: to.valueOf(),
},
}
);
if (response.data) {
if (
data &&
lastOptions &&
data.pageInfo.afterKey !== response.data.pageInfo.afterKey &&
isSameOptions(lastOptions, options) &&
isEqual(timerange, lastTimerange) &&
afterKey
) {
const { series } = data;
setData({
...response.data,
series: [...series, ...response.data.series],
});
} else {
setData(response.data);
}
setLastOptions(options);
setLastTimerange(timerange);
setError(null);
}
} catch (e) {
setError(e);
}
setLoading(false);
})();
示例2: Error
export const getHistogramInterval = (
dateRangeStart: string,
dateRangeEnd: string,
bucketCount?: number
): string => {
const from = DateMath.parse(dateRangeStart);
const to = DateMath.parse(dateRangeEnd);
if (from === undefined) {
throw Error('Invalid dateRangeStart value');
}
if (to === undefined) {
throw Error('Invalid dateRangeEnd value');
}
return `${Math.round(
(to.valueOf() - from.valueOf()) / (bucketCount || QUERY.DEFAULT_BUCKET_COUNT)
)}ms`;
};
示例3: getParsedDate
function getParsedDate(rawDate?: string, opts = {}) {
if (rawDate) {
const parsed = datemath.parse(rawDate, opts);
if (parsed) {
return parsed.toISOString();
}
}
}
示例4: parseAndValidate
function parseAndValidate(str: string): string {
const moment = dateMath.parse(str);
if (!moment || !moment.isValid()) {
throw new Error(`Invalid date/time string: '${str}'`);
}
return moment.toISOString();
}
示例5: validateParams
export function validateParams(params: any, type: string) {
switch (type) {
case 'date':
const moment = typeof params === 'string' ? dateMath.parse(params) : null;
return Boolean(typeof params === 'string' && moment && moment.isValid());
case 'ip':
try {
return Boolean(new Ipv4Address(params));
} catch (e) {
return false;
}
default:
return true;
}
}
示例6: calculateBounds
export function calculateBounds(timeRange: TimeRange, options: CalculateBoundsOptions = {}) {
return {
min: dateMath.parse(timeRange.from, { forceNow: options.forceNow }),
max: dateMath.parse(timeRange.to, { roundUp: true, forceNow: options.forceNow }),
};
}
示例7:
import {
deleteAllQuery,
setAbsoluteRangeDatePicker,
setDuration,
setQuery,
setRelativeRangeDatePicker,
startAutoReload,
stopAutoReload,
toggleTimelineLinkTo,
setTimelineRangeDatePicker,
} from './actions';
import { toggleLockTimeline, updateInputTimerange } from './helpers';
import { InputsModel, TimeRange } from './model';
export type InputsState = InputsModel;
const momentDate = dateMath.parse('now-24h');
export const initialInputsState: InputsState = {
global: {
timerange: {
kind: 'relative',
fromStr: 'now-24h',
toStr: 'now',
from: momentDate ? momentDate.valueOf() : 0,
to: Date.now(),
},
query: [],
policy: {
kind: 'manual',
duration: 300000,
},
linkTo: ['timeline'],