How to use cronstrue - 10 common examples

To help you get started, we’ve selected a few cronstrue examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plotly / falcon / app / components / Settings / cron-picker / cron-helpers.js View on Github external
export function mapCronToHourFormat(cronExpression) {
    try {
        cronstrue.toString(cronExpression);
    } catch (_) {
        return null;
    }

    const cronParts = cronExpression.split(' ');
    if (cronParts.length === 6) {
        // disregard seconds component
        cronParts.shift();
    }
    const [cronMinute, cronHour, cronDayOfMonth, cronMonth, cronDaysOfWeek] = cronParts;

    const time = {};
    time.minute = cronMinute.includes('*') ? 0 : Number(cronMinute);
    time.date = cronDayOfMonth.includes('*') ? 1 : Number(cronDayOfMonth);
    time.month = cronMonth.includes('*') ? 1 : Number(cronMonth);
    time.days = cronDaysOfWeek.includes('*') ? ['MON'] : cronDaysOfWeek.split(',');
github matt-deboer / kuill / pkg / ui / src / components / configuration-pane / ResourceDetails.js View on Github external
getData: ({status, spec, metadata }) => {
      return [
        ['Created:', `${metadata.creationTimestamp} ( ${toHumanizedAge(metadata.creationTimestamp)} ago )`],
        ['Schedule:', `${spec.schedule} ( ${cronstrue.toString(spec.schedule)} )`],
        ['Concurrency Policy:', spec.concurrencyPolicy],
        ['Suspend', spec.suspend],
        // ['Starting Deadline Seconds:', spec.startingDeadlineSeconds || ''],
        ['Selector:', (spec.selector && spec.selector.matchLabels) || ''],
        ['Parallelism:', spec.parallelism || ''],
        ['Last Schedule Time:', status.lastScheduleTime],
        //Completions:			 // => need to get details of owned Jobs for this...
      ]
    },
  },
github elastic / kibana / x-pack / legacy / plugins / rollup / public / crud_app / sections / job_create / steps_config / validate_rollup_cron.js View on Github external
export function validateRollupCron(rollupCron) {
  if (!rollupCron || !rollupCron.trim()) {
    return [
      ,
    ];
  }

  try {
    cronstrue.toString(rollupCron);
  } catch (error) {
    const prefix = 'Error: ';
    const prefixIndex = error.indexOf(prefix);

    // Note: cronstrue ships with a localizable version. Refer to the docs for more
    // info on how we can display a localized error value.
    return error.substring(prefixIndex + prefix.length);
  }

  return undefined;
}
github alibaba / serverless-vscode / src / hovers / ROSTemplateHoverProvider.ts View on Github external
function getCronReadableDesription(cronStr: string): string[] | undefined {
  recordPageView('/getCronReadableDesription');
  let cron: any | undefined;
  try {
    cron = cronParser.parseExpression(cronStr, { utc: true });
  } catch (ex) {  // 此处是故意 ignore。只有当用户表达式书写有问题时会 throw error
    return;
  }
  let readableDescription: string | undefined;
  let sysLocale = osLocale.sync() || 'en';
  const timeZone = jstz.determine().name() || 'Asia/Shanghai';
  readableDescription = cronstrue.toString(cronStr, { locale: sysLocale.replace('-', '_') });
  const prevTime = new Date(cron.prev().toISOString());
  cron.reset();
  const nextTime = new Date(cron.next().toISOString());
  const result = [
    '__CronExpression Description(UTC)__\n',
    `\t${readableDescription}\n`,
    '__Last execution time__\n',
    `\tUTC: ${prevTime.toLocaleString(sysLocale, { timeZone: 'UTC' })}\n`,
    `\t${timeZone}: ${prevTime.toLocaleString(sysLocale, { timeZone: timeZone })}\n`,
    '__Next execution time__\n',
    `\tUTC: ${nextTime.toLocaleString(sysLocale, { timeZone: 'UTC' })}\n`,
    `\t${timeZone}: ${nextTime.toLocaleString(sysLocale, { timeZone: timeZone })}`
  ];
  return result;
}
github fusioncms / fusioncms / fusion / resources / js / components / CronScheduler.vue View on Github external
preview: function() {
				return this.manual ? 'Imports will run manually' : cronstrue.toString(this.expression)
			}
		},
github replicatedhq / kots / web / src / utilities / utilities.js View on Github external
export function getReadableCronDescriptor(expression) {
  return cronstrue.toString(expression);
}
github Zooz / predator / ui / src / features / utils.js View on Github external
export const getTimeFromCronExpr = (cronValue) => {
  let result;
  try {
    result = cronstrue.toString(cronValue)
  } catch (err) {
  }
  return result || ''
};
github dagster-io / dagster / js_modules / dagit / src / schedules / ScheduleRow.tsx View on Github external
const getNaturalLanguageCronString = (cronSchedule: string) => {
    try {
      return cronstrue.toString(cronSchedule);
    } catch {
      return "Invalid cron string";
    }
  };
github taskcluster / taskcluster / infrastructure / tooling / src / generate / generators / monitoring.js View on Github external
Object.entries(requirements[`procs-${name}`]).forEach(([proc, ext]) => {
        if (ext.type === 'cron') {
          res.push([name, proc, `taskcluster.${name}`, ext.deadline, cronstrue.toString(ext.schedule)]);
        }
        if (ext.type === 'background' && ext.subType === 'iterate') {
          res.push([name, proc, `taskcluster.${name}`, 'continuous', 'continuous']);
        }
      });
github Zooz / predator / ui / src / features / components / JobForm / validator.js View on Github external
function cronValidator (value, allState) {
  if (isRequired(value) && !allState.run_immediately) {
    return 'Required if run immediately is unchecked'
  }
  if(value){
    try {
      cronstrue.toString(value)
    } catch (err) {
      return 'illegal cron input'
    }
  }
}
function emailsValidator () {

cronstrue

Convert cron expressions into human readable descriptions

MIT
Latest version published 24 days ago

Package Health Score

83 / 100
Full package analysis

Popular cronstrue functions