feat: add cron desc #59

This commit is contained in:
engigu
2026-03-18 09:08:40 +08:00
parent 75adf36bb5
commit 0f3ffea1b6
5 changed files with 47 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
import cronstrue from 'cronstrue'
import 'cronstrue/locales/zh_CN'
export function getCronDescription(cron: string, lang?: string) {
if (!cron || cron.trim() === '') return ''
try {
const locale = lang?.startsWith('en') ? 'en' : 'zh_CN'
return cronstrue.toString(cron, {
locale,
use24HourTimeFormat: true,
throwExceptionOnParseError: true,
})
} catch (e) {
return ''
}
}