admin管理员组文章数量:1279118
I've been looking all over the internet for an NPM package that could achieve this, but I haven't been able to find one.
What I'm looking for is quite simple on the surface. A cron library that can translate a monthly cron job to human-readable text, while keeping it simple. So for example: if I put in 0 0 14 * *
, I want it to translate to "Monthly". Instead, this translates to "At 00:00 on day-of-month 14." which is an awkward string to display to users.
More examples would be:
0 8 * * *
should translate to "Daily"0 0 10 * *
should also translate to "Monthly"
I want to stay away from making my own proprietary library if possible. Does anyone know if there is any JS package out there that meets my requirements?
I've been looking all over the internet for an NPM package that could achieve this, but I haven't been able to find one.
What I'm looking for is quite simple on the surface. A cron library that can translate a monthly cron job to human-readable text, while keeping it simple. So for example: if I put in 0 0 14 * *
, I want it to translate to "Monthly". Instead, this translates to "At 00:00 on day-of-month 14." which is an awkward string to display to users.
More examples would be:
0 8 * * *
should translate to "Daily"0 0 10 * *
should also translate to "Monthly"
I want to stay away from making my own proprietary library if possible. Does anyone know if there is any JS package out there that meets my requirements?
Share Improve this question edited Apr 25, 2022 at 10:08 Sebastiaan asked Apr 25, 2022 at 10:03 SebastiaanSebastiaan 811 gold badge1 silver badge3 bronze badges 2- stackoverflow./questions/36263810/… – 0stone0 Commented Apr 25, 2022 at 10:05
- @0stone0 I've seen cronstrue, but it returns the long variant of the English string. I'm looking for a shorter version as described above – Sebastiaan Commented Apr 25, 2022 at 10:11
1 Answer
Reset to default 9You can use https://www.npmjs./package/cronstrue
cRonstrue is a JavaScript library that parses a cron expression and outputs a human readable description of the cron schedule.
cronstrue.toString("* * * * *");
> "Every minute"
cronstrue.toString("0 23 ? * MON-FRI");
> "At 11:00 PM, Monday through Friday"
cronstrue.toString("0 23 * * *", { verbose: true });
> "At 11:00 PM, every day"
cronstrue.toString("23 12 * * SUN#2");
> "At 12:23 PM, on the second Sunday of the month"
cronstrue.toString("23 14 * * SUN#2", { use24HourTimeFormat: true });
> "At 14:23, on the second Sunday of the month"
cronstrue.toString("* * * ? * 2-6/2", { dayOfWeekStartIndexZero: false });
> "Every second, every 2 days of the week, Monday through Friday"
cronstrue.toString("* * * 6-8 *", { monthStartIndexZero: true });
> "Every minute, July through September"
本文标签: javascriptPackage to translate a cron to a quotsimplerquot human readable formatStack Overflow
版权声明:本文标题:javascript - Package to translate a cron to a "simpler" human readable format? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741282277a2370074.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论