时间表符号(时间范围)
我有一些代码需要根据时间表做事情:例如,在工作时间做 X,下班后做 Y。时间表将由我们的客户定义,所以我需要一个可以由人们编写并由我的程序解析的符号。我在想这样的事情:
12/25:0730-1730 Do Y
[Mo-Fr]:0730-1730 Do X
[Mo-Tu]:1730-0730 Do Y
Fr:1730-Mo:0730 Do Y
每周肯定会有变化。每年的变化(假期)似乎是可能的。我想要一种高效且灵活的符号。
我还需要java代码来解析时间范围并告诉我给定的日期时间在哪个范围内。
我在网上搜索过但什么也没找到。最接近的是 CRON 表示法,这不太符合我的需要。
有人知道现有的符号定义和实现吗?
谢谢,
I have some code which needs to do things based on a schedule: e.g. during business hours do X, after hours do Y. The schedule will be defined by our customer's so I need a notation which can be written by people and parsed by my program. I'm thinking of something like:
12/25:0730-1730 Do Y
[Mo-Fr]:0730-1730 Do X
[Mo-Tu]:1730-0730 Do Y
Fr:1730-Mo:0730 Do Y
There will definitely be weekly variation. Yearly variation (holidays) seems likely. I would like a notation that is efficient and flexible.
I also need java code which will parse the time ranges and tell me which range a given date time is in.
I've searched the web and found nothing. Closest is CRON notation, which is not quite what I need.
Any one know of an existing notation definition and implementation?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 Java Joda 时间(Scala 包装器 scala-time) 是一个强大的时间计算库。您可以查看 google-rfc-2445 ,它的功能与您类似正在要求(?)。
如果您正在寻找 Java 调度程序 http://www.quartz-scheduler.org/ 是不错的选择。
For Java Joda time (Scala wrapper scala-time) is a powerful library for time calculations. You could look at the google-rfc-2445 which does something like what you are asking for (?).
If you are looking for a Java scheduler http://www.quartz-scheduler.org/ is a good option.
我认为你不会找到现成的东西。在这种情况下,最好自己实现并完全控制代码。您可以使用 antlr 创建解析器。
在语法中添加优先级概念。然后安排一些事情会更容易
I don't think you will find something out of the box. In such cases it's better to do the implementation by yourself and have a full control of the code. You can use antlr to create a parser.
Add a notion of priority to your syntax. Then it will be easier to schedule someting