本文整理汇总了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'],