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


TypeScript moment_wrapper.toUtc函數代碼示例

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


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

示例1: toUtc

const parseRawTime = (value): TimeFragment => {
  if (value === null) {
    return null;
  }

  if (value.indexOf('now') !== -1) {
    return value;
  }
  if (value.length === 8) {
    return toUtc(value, 'YYYYMMDD');
  }
  if (value.length === 15) {
    return toUtc(value, 'YYYYMMDDTHHmmss');
  }
  // Backward compatibility
  if (value.length === 19) {
    return toUtc(value, 'YYYY-MM-DD HH:mm:ss');
  }

  if (!isNaN(value)) {
    const epoch = parseInt(value, 10);
    return toUtc(epoch);
  }

  return null;
};
開發者ID:grafana,項目名稱:grafana,代碼行數:26,代碼來源:explore.ts

示例2: beforeEach

 beforeEach(() => {
   builder = new AzureMonitorFilterBuilder(
     'Percentage CPU',
     toUtc('2017-08-22 06:00'),
     toUtc('2017-08-22 07:00'),
     'PT1H',
     '3m'
   );
 });
開發者ID:grafana,項目名稱:grafana,代碼行數:9,代碼來源:azure_monitor_filter_builder.test.ts

示例3: zoomOut

  zoomOut(e: any, factor: number) {
    const range = this.timeRange();

    const timespan = range.to.valueOf() - range.from.valueOf();
    const center = range.to.valueOf() - timespan / 2;

    const to = center + (timespan * factor) / 2;
    const from = center - (timespan * factor) / 2;

    this.setTime({ from: toUtc(from), to: toUtc(to) });
  }
開發者ID:grafana,項目名稱:grafana,代碼行數:11,代碼來源:TimeSrv.ts

示例4: beforeEach

    beforeEach(async () => {
      createDatasource({
        url: 'http://es.com',
        index: '[asd-]YYYY.MM.DD',
        jsonData: { interval: 'Daily', esVersion: '2' },
      });

      ctx.backendSrv.datasourceRequest = jest.fn(options => {
        requestOptions = options;
        return Promise.resolve({
          data: {
            responses: [
              {
                aggregations: {
                  '1': {
                    buckets: [
                      {
                        doc_count: 10,
                        key: 1000,
                      },
                    ],
                  },
                },
              },
            ],
          },
        });
      });

      query = {
        range: {
          from: toUtc([2015, 4, 30, 10]),
          to: toUtc([2015, 5, 1, 10]),
        },
        targets: [
          {
            alias: '$varAlias',
            bucketAggs: [{ type: 'date_histogram', field: '@timestamp', id: '1' }],
            metrics: [{ type: 'count', id: '1' }],
            query: 'escape\\:test',
          },
        ],
      };

      result = await ctx.ds.query(query);

      parts = requestOptions.data.split('\n');
      header = angular.fromJson(parts[0]);
    });
開發者ID:grafana,項目名稱:grafana,代碼行數:49,代碼來源:datasource.test.ts

示例5: toUtc

      const fromUser = text => {
        if (text.indexOf('now') !== -1) {
          if (!dateMath.isValid(text)) {
            ngModel.$setValidity('error', false);
            return undefined;
          }
          ngModel.$setValidity('error', true);
          return text;
        }

        let parsed;
        if ($scope.ctrl.isUtc) {
          parsed = toUtc(text, format);
        } else {
          parsed = dateTime(text, format);
        }

        if (!parsed.isValid()) {
          ngModel.$setValidity('error', false);
          return undefined;
        }

        ngModel.$setValidity('error', true);
        return parsed;
      };
開發者ID:grafana,項目名稱:grafana,代碼行數:25,代碼來源:validation.ts

示例6: getIndexForToday

 getIndexForToday() {
   if (this.interval) {
     return toUtc().format(this.pattern);
   } else {
     return this.pattern;
   }
 }
開發者ID:grafana,項目名稱:grafana,代碼行數:7,代碼來源:index_pattern.ts

示例7: describe

  describe('When performing query', () => {
    const options = {
      range: {
        from: toUtc('2017-08-22T20:00:00Z'),
        to: toUtc('2017-08-22T23:59:00Z'),
      },
      rangeRaw: {
        from: 'now-4h',
        to: 'now',
      },
      targets: [
        {
          refId: 'A',
        },
      ],
    };

    describe('and no time series data is returned', () => {
      let ds;
      const response = {
        results: {
          A: {
            refId: 'A',
            meta: {
              rawQuery: 'arawquerystring',
            },
            series: null,
            tables: null,
          },
        },
      };

      beforeEach(() => {
        const backendSrv = ({
          datasourceRequest: async () => Promise.resolve({ status: 200, data: response }),
        } as unknown) as BackendSrv;
        ds = new StackdriverDataSource(instanceSettings, backendSrv, templateSrv, timeSrv);
      });

      it('should return a list of datapoints', () => {
        return ds.query(options).then(results => {
          expect(results.data.length).toBe(0);
        });
      });
    });
  });
開發者ID:grafana,項目名稱:grafana,代碼行數:46,代碼來源:datasource.test.ts

示例8: parseUrlParam

  private parseUrlParam(value: any) {
    if (value.indexOf('now') !== -1) {
      return value;
    }
    if (value.length === 8) {
      return toUtc(value, 'YYYYMMDD');
    }
    if (value.length === 15) {
      return toUtc(value, 'YYYYMMDDTHHmmss');
    }

    if (!isNaN(value)) {
      const epoch = parseInt(value, 10);
      return toUtc(epoch);
    }

    return null;
  }
開發者ID:grafana,項目名稱:grafana,代碼行數:18,代碼來源:TimeSrv.ts

示例9: onMouseUp

  onMouseUp() {
    $(document).unbind('mouseup', this.mouseUpHandler.bind(this));
    this.mouseUpHandler = null;
    this.selection.active = false;

    const selectionRange = Math.abs(this.selection.x2 - this.selection.x1);
    if (this.selection.x2 >= 0 && selectionRange > MIN_SELECTION_WIDTH) {
      const timeFrom = this.xScale.invert(Math.min(this.selection.x1, this.selection.x2) - this.yAxisWidth);
      const timeTo = this.xScale.invert(Math.max(this.selection.x1, this.selection.x2) - this.yAxisWidth);

      this.ctrl.timeSrv.setTime({
        from: toUtc(timeFrom),
        to: toUtc(timeTo),
      });
    }

    this.clearSelection();
  }
開發者ID:grafana,項目名稱:grafana,代碼行數:18,代碼來源:rendering.ts

示例10: getFieldFromSource

    return this.post('_msearch', payload).then(res => {
      const list = [];
      const hits = res.responses[0].hits.hits;

      const getFieldFromSource = (source, fieldName) => {
        if (!fieldName) {
          return;
        }

        const fieldNames = fieldName.split('.');
        let fieldValue = source;

        for (let i = 0; i < fieldNames.length; i++) {
          fieldValue = fieldValue[fieldNames[i]];
          if (!fieldValue) {
            console.log('could not find field in annotation: ', fieldName);
            return '';
          }
        }

        return fieldValue;
      };

      for (let i = 0; i < hits.length; i++) {
        const source = hits[i]._source;
        let time = getFieldFromSource(source, timeField);
        if (typeof hits[i].fields !== 'undefined') {
          const fields = hits[i].fields;
          if (_.isString(fields[timeField]) || _.isNumber(fields[timeField])) {
            time = fields[timeField];
          }
        }

        const event = {
          annotation: annotation,
          time: toUtc(time).valueOf(),
          text: getFieldFromSource(source, textField),
          tags: getFieldFromSource(source, tagsField),
        };

        // legacy support for title tield
        if (annotation.titleField) {
          const title = getFieldFromSource(source, annotation.titleField);
          if (title) {
            event.text = title + '\n' + event.text;
          }
        }

        if (typeof event.tags === 'string') {
          event.tags = event.tags.split(',');
        }

        list.push(event);
      }
      return list;
    });
開發者ID:grafana,項目名稱:grafana,代碼行數:56,代碼來源:datasource.ts


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