utils.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import moment from 'moment';
  2. import {getFormat} from 'sentry/utils/dates';
  3. import {TimeWindow, TimeWindowData} from './types';
  4. // Stores options and data which correspond to each selectable time window
  5. export const timeWindowConfig: TimeWindowData = {
  6. '1h': {
  7. cursorLabelFormat: getFormat({timeOnly: true, seconds: true}),
  8. elapsedMinutes: 60,
  9. timeMarkerInterval: 10,
  10. dateTimeProps: {timeOnly: true},
  11. },
  12. '24h': {
  13. cursorLabelFormat: getFormat({timeOnly: true}),
  14. elapsedMinutes: 60 * 24,
  15. timeMarkerInterval: 60 * 4,
  16. dateTimeProps: {timeOnly: true},
  17. },
  18. '7d': {
  19. cursorLabelFormat: getFormat(),
  20. elapsedMinutes: 60 * 24 * 7,
  21. timeMarkerInterval: 60 * 24,
  22. dateTimeProps: {},
  23. },
  24. '30d': {
  25. cursorLabelFormat: getFormat({dateOnly: true}),
  26. elapsedMinutes: 60 * 24 * 30,
  27. timeMarkerInterval: 60 * 24 * 5,
  28. dateTimeProps: {dateOnly: true},
  29. },
  30. };
  31. export function getStartFromTimeWindow(end: Date, timeWindow: TimeWindow): Date {
  32. const {elapsedMinutes} = timeWindowConfig[timeWindow];
  33. const start = moment(end).subtract(elapsedMinutes, 'minute');
  34. return start.toDate();
  35. }