一个生成 cron 中文描述的 JS 库

2022-10-16 22:26:24 +08:00
 ikesnowy

好像没有找到特别合适的库,只能自己随便撸一个了,下面是一些例子:

humanizeCronInChinese('* * * * *'); // 每分钟
humanizeCronInChinese('0 0 * * *'); // 每日 00:00
humanizeCronInChinese('0 0 1 * *'); // 每月 1 日 00:00
humanizeCronInChinese('*/2 * * * *'); // 每隔 2 分钟
humanizeCronInChinese('45 4 1,10,20 * *') // 每月 1,10,20 日 04:45
humanizeCronInChinese('0 0 * * 1-5') // 每周一~周五 00:00

https://github.com/ikesnowy/cron-chinese

征集一些奇怪的 cron 测试用例 hhhh

1867 次点击
所在节点    分享创造
8 条回复
panlatent
2022-10-16 23:23:21 +08:00
有个 C# 库是做这个的,支持国际化。我移植过它的 PHP 版本。
steins2628
2022-10-16 23:45:14 +08:00
cronstrue 其实支持类似的国际化,不过楼主这个也不错
pigmen
2022-10-16 23:58:33 +08:00
kkeep
2022-10-17 00:31:34 +08:00
crintab.guru
flashBee233
2022-10-17 11:19:03 +08:00
测试了 3 楼的,确实可以实现楼主的需求
ikesnowy
2022-10-17 11:54:59 +08:00
@flashBee233

这个我看过,当时试了试他们的 demo ,然后就看到了这个……

https://v2ex.com/i/zF877V73.png

然后就决定还是自己写了,语序还能好一点。
alanhe421
2022-10-17 12:16:23 +08:00
@kkeep typo
正确网址是: https://crontab.guru/,不错,👍
kkeep
2022-10-17 23:12:14 +08:00
@18519017871 对。手机打的没注意

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/887378

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX