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


TypeScript datemath.parse函數代碼示例

本文整理匯總了TypeScript中@grafana/ui/src/utils/datemath.parse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript parse函數的具體用法?TypeScript parse怎麽用?TypeScript parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了parse函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

export const getTimeRange = (timeZone: TimeZone, rawRange: RawTimeRange): TimeRange => {
  return {
    from: dateMath.parse(rawRange.from, false, timeZone.raw as any),
    to: dateMath.parse(rawRange.to, true, timeZone.raw as any),
    raw: rawRange,
  };
};
開發者ID:grafana,項目名稱:grafana,代碼行數:7,代碼來源:explore.ts

示例2: applyPanelTimeOverrides

export function applyPanelTimeOverrides(panel: PanelModel, timeRange: TimeRange): TimeOverrideResult {
  const newTimeData = {
    timeInfo: '',
    timeRange: timeRange,
  };

  if (panel.timeFrom) {
    const timeFromInterpolated = templateSrv.replace(panel.timeFrom, panel.scopedVars);
    const timeFromInfo = rangeUtil.describeTextRange(timeFromInterpolated);
    if (timeFromInfo.invalid) {
      newTimeData.timeInfo = 'invalid time override';
      return newTimeData;
    }

    if (_isString(timeRange.raw.from)) {
      const timeFromDate = dateMath.parse(timeFromInfo.from);
      newTimeData.timeInfo = timeFromInfo.display;
      newTimeData.timeRange = {
        from: timeFromDate,
        to: dateMath.parse(timeFromInfo.to),
        raw: {
          from: timeFromInfo.from,
          to: timeFromInfo.to,
        },
      };
    }
  }

  if (panel.timeShift) {
    const timeShiftInterpolated = templateSrv.replace(panel.timeShift, panel.scopedVars);
    const timeShiftInfo = rangeUtil.describeTextRange(timeShiftInterpolated);
    if (timeShiftInfo.invalid) {
      newTimeData.timeInfo = 'invalid timeshift';
      return newTimeData;
    }

    const timeShift = '-' + timeShiftInterpolated;
    newTimeData.timeInfo += ' timeshift ' + timeShift;
    const from = dateMath.parseDateMath(timeShift, newTimeData.timeRange.from, false);
    const to = dateMath.parseDateMath(timeShift, newTimeData.timeRange.to, true);

    newTimeData.timeRange = {
      from,
      to,
      raw: {
        from,
        to,
      },
    };
  }

  if (panel.hideTimeOverride) {
    newTimeData.timeInfo = '';
  }

  return newTimeData;
}
開發者ID:grafana,項目名稱:grafana,代碼行數:57,代碼來源:panel.ts

示例3: parseRawTime

export const getTimeRangeFromUrl = (range: RawTimeRange, timeZone: TimeZone): TimeRange => {
  const raw = {
    from: parseRawTime(range.from),
    to: parseRawTime(range.to),
  };

  return {
    from: dateMath.parse(raw.from, false, timeZone.raw as any),
    to: dateMath.parse(raw.to, true, timeZone.raw as any),
    raw,
  };
};
開發者ID:grafana,項目名稱:grafana,代碼行數:12,代碼來源:explore.ts

示例4: timeRange

  timeRange(): TimeRange {
    // make copies if they are moment  (do not want to return out internal moment, because they are mutable!)
    const raw = {
      from: isDateTime(this.time.from) ? dateTime(this.time.from) : this.time.from,
      to: isDateTime(this.time.to) ? dateTime(this.time.to) : this.time.to,
    };

    const timezone = this.dashboard && this.dashboard.getTimezone();

    return {
      from: dateMath.parse(raw.from, false, timezone),
      to: dateMath.parse(raw.to, true, timezone),
      raw: raw,
    };
  }
開發者ID:grafana,項目名稱:grafana,代碼行數:15,代碼來源:TimeSrv.ts

示例5: if

  this.translateTime = (date, roundUp, timezone) => {
    if (_.isString(date)) {
      if (date === 'now') {
        return 'now';
      } else if (date.indexOf('now-') >= 0 && date.indexOf('/') === -1) {
        date = date.substring(3);
        date = date.replace('m', 'min');
        date = date.replace('M', 'mon');
        return date;
      }
      date = dateMath.parse(date, roundUp, timezone);
    }

    // graphite' s from filter is exclusive
    // here we step back one minute in order
    // to guarantee that we get all the data that
    // exists for the specified range
    if (roundUp) {
      if (date.get('s')) {
        date.add(1, 'm');
      }
    } else if (roundUp === false) {
      if (date.get('s')) {
        date.subtract(1, 'm');
      }
    }

    return date.unix();
  };
開發者ID:grafana,項目名稱:grafana,代碼行數:29,代碼來源:datasource.ts

示例6: convertToTSDBTime

  convertToTSDBTime(date, roundUp, timezone) {
    if (date === 'now') {
      return null;
    }

    date = dateMath.parse(date, roundUp, timezone);
    return date.valueOf();
  }
開發者ID:grafana,項目名稱:grafana,代碼行數:8,代碼來源:datasource.ts

示例7: getInfluxTime

  getInfluxTime(date, roundUp, timezone) {
    if (_.isString(date)) {
      if (date === 'now') {
        return 'now()';
      }

      const parts = /^now-(\d+)([dhms])$/.exec(date);
      if (parts) {
        const amount = parseInt(parts[1], 10);
        const unit = parts[2];
        return 'now() - ' + amount + unit;
      }
      date = dateMath.parse(date, roundUp, timezone);
    }

    return date.valueOf() + 'ms';
  }
開發者ID:grafana,項目名稱:grafana,代碼行數:17,代碼來源:datasource.ts

示例8:

 timeRange: () => {
   return {
     from: dateMath.parse(timeSrv.time.from, false),
     to: dateMath.parse(timeSrv.time.to, true),
   };
 },
開發者ID:grafana,項目名稱:grafana,代碼行數:6,代碼來源:datasource.test.ts

示例9: convertToCloudWatchTime

 convertToCloudWatchTime(date, roundUp) {
   if (_.isString(date)) {
     date = dateMath.parse(date, roundUp);
   }
   return Math.round(date.valueOf() / 1000);
 }
開發者ID:johntdyer,項目名稱:grafana,代碼行數:6,代碼來源:datasource.ts

示例10:

 timeRange: jest.fn(() => {
   return {
     from: dateMath.parse(this.time.from, false),
     to: dateMath.parse(this.time.to, true),
   };
 }),
開發者ID:grafana,項目名稱:grafana,代碼行數:6,代碼來源:datasource.test.ts


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