示例#1
0
    it('should translate index pattern to current day', function() {
      var requestOptions;
      ctx.backendSrv.datasourceRequest = function(options) {
        requestOptions = options;
        return ctx.$q.when({data: {}});
      };

      ctx.ds.testDatasource();
      ctx.$rootScope.$apply();

      var today = moment.utc().format("YYYY.MM.DD");
      expect(requestOptions.url).to.be("http://es.com/asd-" + today + '/_mapping');
    });
示例#2
0
export function setupRequest(req: Legacy.Request): Setup {
  const query = (req.query as unknown) as APMRequestQuery;
  const cluster = req.server.plugins.elasticsearch.getCluster('data');
  const uiSettings = req.getUiSettingsService();
  const config = req.server.config();
  const apmIndices = getApmIndices(config);

  const client: ESClient = async (type, params) => {
    const includeFrozen = await uiSettings.get('search:includeFrozen');

    const nextParams = {
      ...addFilterForLegacyData(apmIndices, params), // filter out pre-7.0 data
      ignore_throttled: !includeFrozen, // whether to query frozen indices or not
      rest_total_hits_as_int: true // ensure that ES returns accurate hits.total with pre-6.6 format
    };

    if (query._debug) {
      console.log(`DEBUG ES QUERY:`);
      console.log('includeFrozen: ', includeFrozen);
      console.log(
        `${req.method.toUpperCase()} ${req.url.pathname} ${JSON.stringify(
          query
        )}`
      );
      console.log(`GET ${nextParams.index}/_search`);
      console.log(JSON.stringify(nextParams.body, null, 4));
    }

    return cluster.callWithRequest(req, type, nextParams);
  };

  return {
    start: moment.utc(query.start).valueOf(),
    end: moment.utc(query.end).valueOf(),
    esFilterQuery: decodeEsQuery(query.esFilterQuery),
    client,
    config
  };
}
 var data = body.results.map((m: any) => {
   return {
     "key" : m.value_1 + "_" + m.value_2 + "_" + m.value_3,
     "source" : "silver-surfer",
     data : {
       "time": moment.utc(m.value_1, "DD.MM.YYYY - HH:mm").toISOString(),
       "ticket": m.value_2,
       "oper": m.value_3 == "Продавать" ? "sell" : "buy",
       "stop": m.number ? m.number : null,
       "force": m.value_4 && m.value_4 != "Штиль" ? parseInt(m.value_4) : null
     }
   }
 });
const withSection = (referenceDateTime: moment.Moment) => (
  message: Message
): MessageWithSection => {
  const today = moment(referenceDateTime).startOf('day');
  const yesterday = moment(referenceDateTime)
    .subtract(1, 'day')
    .startOf('day');
  const thisWeek = moment(referenceDateTime).startOf('isoWeek');
  const thisMonth = moment(referenceDateTime).startOf('month');

  const messageReceivedDate = moment.utc(message.received_at);
  if (messageReceivedDate.isAfter(today)) {
    return {
      order: 0,
      type: 'today',
      message,
    };
  }
  if (messageReceivedDate.isAfter(yesterday)) {
    return {
      order: 1,
      type: 'yesterday',
      message,
    };
  }
  if (messageReceivedDate.isAfter(thisWeek)) {
    return {
      order: 2,
      type: 'thisWeek',
      message,
    };
  }
  if (messageReceivedDate.isAfter(thisMonth)) {
    return {
      order: 3,
      type: 'thisMonth',
      message,
    };
  }

  const month: number = messageReceivedDate.month();
  const year: number = messageReceivedDate.year();

  return {
    order: year * 100 + month,
    type: 'yearMonth',
    month,
    year,
    message,
  };
};
 parseTimeStamp(dateTime: string, format: string): moment.Moment {
     try {
         let m = moment.utc(dateTime, format, false);
         if (!m.isValid()) {
             console.warn("Cannot parse TimeStamp. dateTime=" + dateTime + "; format=" + format);
             return null;
         }
         return m;
     }
     catch (ex) {
         console.warn(ex);
         return null;
     }
 }
示例#6
0
文件: lib.ts 项目: anydown/ganttdown
  var tasks = textData.split(/\r|\n|\r\n/).map(function (line) {
    line = line.replace(///g, "/");
    line = line.replace(/ /g, " ");
    line = line.replace(/〜/g, " ");
    var args = line.split(" ");

    var inputPattern = [
      "MM/DD",
      "MM月DD日",
      "YYYY年MM月DD日",
      "YYYY/MM/DD",
      "YYYY-MM-DD"
    ];

    var startTime:moment.Moment = moment.utc(args[1], inputPattern);
    var endTime:moment.Moment | null = null
    if(args[2]){
      endTime = moment.utc(args[2], inputPattern);
    }

    if (args.length > 2) {
      return {
        name: args[0],
        start: startTime.unix() * 1000,
        end: endTime.unix() * 1000 + 1000 * 60 * 60 * 24
      };
    }
    if (args.length === 2){
      return {
        name: args[0],
        start: startTime.unix() * 1000,
        end: null
      };
    }

    return null;
  }).filter(function (item) { return item });
示例#7
0
function convertToMoment(input: any, timeZone: string, timeZoneOffset: number | null, locale: string): moment.Moment {
  let mom: moment.Moment

  if (timeZone === 'local') {
    mom = moment(input)

  } else if (timeZone === 'UTC') {
    mom = moment.utc(input)

  } else if ((moment as any).tz) {
    mom = (moment as any).tz(input, timeZone)

  } else {
    mom = moment.utc(input)

    if (timeZoneOffset != null) {
      mom.utcOffset(timeZoneOffset)
    }
  }

  mom.locale(locale)

  return mom
}
示例#8
0
    fn: (_context, args) => {
      const { position, min, max, ...rest } = args;

      if (!Object.values(Position).includes(position)) {
        throw new Error(`Invalid position: '${args.position}'`);
      }

      const minVal = typeof min === 'string' ? moment.utc(min).valueOf() : min;
      const maxVal = typeof max === 'string' ? moment.utc(max).valueOf() : max;

      // This != check is not !== in order to handle NaN cases properly.
      if (minVal != null && isNaN(minVal)) {
        throw new Error(
          `Invalid date string: '${
            args.min
          }'. 'min' must be a number, date in ms, or ISO8601 date string`
        );
      }

      // This != check is not !== in order to handle NaN cases properly.
      if (maxVal != null && isNaN(maxVal)) {
        throw new Error(
          `Invalid date string: '${
            args.max
          }'. 'max' must be a number, date in ms, or ISO8601 date string`
        );
      }

      return {
        max: maxVal,
        min: minVal,
        type: 'axisConfig',
        position,
        ...rest,
      };
    },
示例#9
0
const findLastFullBucket = (
  buckets: InfraSnapshotMetricsBucket[],
  options: InfraSnapshotRequestOptions
) => {
  const to = moment.utc(options.timerange.to);
  const bucketSize = getIntervalInSeconds(options.timerange.interval);
  return buckets.reduce((current, item) => {
    const itemKey = isNumber(item.key) ? item.key : parseInt(item.key, 10);
    const date = moment.utc(itemKey + bucketSize * 1000);
    if (!date.isAfter(to) && item.doc_count > 0) {
      return item;
    }
    return current;
  }, last(buckets));
};
    beforeEach(async () => {
      ctx.backendSrv.datasourceRequest = options => {
        if (options.url.indexOf('Microsoft.OperationalInsights/workspaces') > -1) {
          return ctx.$q.when({ data: workspaceResponse, status: 200 });
        } else {
          return ctx.$q.when({ data: tableResponse, status: 200 });
        }
      };

      annotationResults = await ctx.ds.annotationQuery({
        annotation: {
          rawQuery: 'Heartbeat | where $__timeFilter()| project TimeGenerated, Text=Computer, tags="test"',
          workspace: 'abc1b44e-3e57-4410-b027-6cc0ae6dee67',
        },
        range: {
          from: moment.utc('2017-08-22T20:00:00Z'),
          to: moment.utc('2017-08-22T23:59:00Z'),
        },
        rangeRaw: {
          from: 'now-4h',
          to: 'now',
        },
      });
    });