當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript datemath.parse函數代碼示例

本文整理匯總了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);
 })();
開發者ID:elastic,項目名稱:kibana,代碼行數:60,代碼來源:use_metrics_explorer_data.ts

示例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`;
};
開發者ID:,項目名稱:,代碼行數:17,代碼來源:

示例3: getParsedDate

function getParsedDate(rawDate?: string, opts = {}) {
  if (rawDate) {
    const parsed = datemath.parse(rawDate, opts);
    if (parsed) {
      return parsed.toISOString();
    }
  }
}
開發者ID:njd5475,項目名稱:kibana,代碼行數:8,代碼來源:urlParams.ts

示例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();
      }
開發者ID:elastic,項目名稱:kibana,代碼行數:9,代碼來源:timefilter.ts

示例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;
  }
}
開發者ID:elastic,項目名稱:kibana,代碼行數:15,代碼來源:filter_editor_utils.ts

示例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 }),
  };
}
開發者ID:elastic,項目名稱:kibana,代碼行數:6,代碼來源:get_time.ts

示例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'],
開發者ID:,項目名稱:,代碼行數:31,代碼來源:


注:本文中的@elastic/datemath.parse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。