@grafana/data#TimeOption TypeScript Examples

The following examples show how to use @grafana/data#TimeOption. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TimePicker.tsx    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
quickOptions: TimeOption[] = [
  { from: 'now-5m', to: 'now', display: '最近5分钟', section: 3 },
  { from: 'now-15m', to: 'now', display: '最近15分钟', section: 3 },
  { from: 'now-30m', to: 'now', display: '最近30分钟', section: 3 },
  { from: 'now-1h', to: 'now', display: '最近1小时', section: 3 },
  { from: 'now-3h', to: 'now', display: '最近3小时', section: 3 },
  { from: 'now-6h', to: 'now', display: '最近6小时', section: 3 },
  { from: 'now-12h', to: 'now', display: '最近12小时', section: 3 },
  { from: 'now-24h', to: 'now', display: '最近24小时', section: 3 },
  { from: 'now-2d', to: 'now', display: '最近2天', section: 3 },
  { from: 'now-7d', to: 'now', display: '最近2天', section: 3 },
  { from: 'now-30d', to: 'now', display: '最近30天', section: 3 },
  { from: 'now-90d', to: 'now', display: '最近90天', section: 3 },
  { from: 'now-6M', to: 'now', display: '最近6个月', section: 3 },
  { from: 'now-1y', to: 'now', display: '最近1年', section: 3 },
  { from: 'now-2y', to: 'now', display: '最近2年', section: 3 },
  { from: 'now-5y', to: 'now', display: '最近5年', section: 3 },
]
Example #2
Source File: TimePicker.tsx    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
otherOptions: TimeOption[] = [
  { from: 'now-1d/d', to: 'now-1d/d', display: '昨天', section: 3 },
  { from: 'now-2d/d', to: 'now-2d/d', display: '前天', section: 3 },
  { from: 'now-7d/d', to: 'now-7d/d', display: '上周的今天', section: 3 },
  { from: 'now-1w/w', to: 'now-1w/w', display: '前一周', section: 3 },
  { from: 'now-1M/M', to: 'now-1M/M', display: '前一月', section: 3 },
  { from: 'now-1y/y', to: 'now-1y/y', display: '前一年', section: 3 },
  { from: 'now/d', to: 'now/d', display: '今天', section: 3 },
  { from: 'now/d', to: 'now', display: '今天到目前为止', section: 3 },
  { from: 'now/w', to: 'now/w', display: '这个周', section: 3 },
  { from: 'now/w', to: 'now', display: '到这周为止', section: 3 },
  { from: 'now/M', to: 'now/M', display: '这个月', section: 3 },
  { from: 'now/M', to: 'now', display: '本月至今', section: 3 },
  { from: 'now/y', to: 'now/y', display: '这一年', section: 3 },
  { from: 'now/y', to: 'now', display: '今年至今', section: 3 },
]
Example #3
Source File: mapper.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
mapOptionToTimeRange = (option: TimeOption, timeZone?: TimeZone): TimeRange => {
  return {
    from: stringToDateTime(option.from, false, timeZone),
    to: stringToDateTime(option.to, true, timeZone),
    raw: {
      from: option.from,
      to: option.to,
    },
  };
}
Example #4
Source File: mapper.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
mapRangeToTimeOption = (range: TimeRange, timeZone?: TimeZone): TimeOption => {
  const formattedFrom = stringToDateTime(range.from, false, timeZone).format(TIME_FORMAT);
  const formattedTo = stringToDateTime(range.to, true, timeZone).format(TIME_FORMAT);
  const from = dateTimeToString(range.from, timeZone);
  const to = dateTimeToString(range.to, timeZone);

  return {
    from,
    to,
    section: 3,
    display: `${formattedFrom} to ${formattedTo}`,
  };
}
Example #5
Source File: TimePickerContent.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
function mapToHistoryOptions(ranges?: TimeRange[], timeZone?: TimeZone): TimeOption[] {
  if (!Array.isArray(ranges) || ranges.length === 0) {
    return [];
  }
  return ranges.slice(ranges.length - 4).map(range => mapRangeToTimeOption(range, timeZone));
}
Example #6
Source File: TimeRangeList.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
function keyForOption(option: TimeOption, index: number): string {
  return `${option.from}-${option.to}-${index}`;
}
Example #7
Source File: TimeRangeList.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
function isEqual(x: TimeOption, y?: TimeRange): boolean {
  if (!y || !x) {
    return false;
  }
  return y.raw.from === x.from && y.raw.to === x.to;
}