Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}