crontabAsText.tsx 513 B

1234567891011121314151617181920212223
  1. import cronstrue from 'cronstrue';
  2. import {shouldUse24Hours} from 'sentry/utils/dates';
  3. /**
  4. * Display a human readible label of a crontab expression
  5. */
  6. export function crontabAsText(crontabInput: string | null): string | null {
  7. if (!crontabInput) {
  8. return null;
  9. }
  10. let parsedSchedule: string;
  11. try {
  12. parsedSchedule = cronstrue.toString(crontabInput, {
  13. verbose: false,
  14. use24HourTimeFormat: shouldUse24Hours(),
  15. });
  16. } catch (_e) {
  17. return null;
  18. }
  19. return parsedSchedule;
  20. }