scheduleAsText.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import {t, tn} from 'sentry/locale';
  2. import type {MonitorConfig} from 'sentry/views/monitors/types';
  3. import {ScheduleType} from 'sentry/views/monitors/types';
  4. import {crontabAsText} from './crontabAsText';
  5. /**
  6. * Display a human readable label for the shedule of a MonitorConfig
  7. */
  8. export function scheduleAsText(config: MonitorConfig) {
  9. // Crontab format uses cronstrue
  10. if (config.schedule_type === ScheduleType.CRONTAB) {
  11. const parsedSchedule = crontabAsText(config.schedule);
  12. return parsedSchedule ?? t('Unknown schedule');
  13. }
  14. if (config.schedule_type === ScheduleType.INTERVAL) {
  15. // Interval format is simpler
  16. const [value, timeUnit] = config.schedule;
  17. if (timeUnit === 'minute') {
  18. return tn('Every minute', 'Every %s minutes', value);
  19. }
  20. if (timeUnit === 'hour') {
  21. return tn('Every hour', 'Every %s hours', value);
  22. }
  23. if (timeUnit === 'day') {
  24. return tn('Every day', 'Every %s days', value);
  25. }
  26. if (timeUnit === 'week') {
  27. return tn('Every week', 'Every %s weeks', value);
  28. }
  29. if (timeUnit === 'month') {
  30. return tn('Every month', 'Every %s months', value);
  31. }
  32. if (timeUnit === 'year') {
  33. return tn('Every year', 'Every %s years', value);
  34. }
  35. }
  36. return t('Unknown schedule');
  37. }