How to use the cronstrue/i18n.toString function in cronstrue

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 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;
}

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