Search code examples
javadatetimenotation

Schedule notation (time ranges)


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,


Solution

  • 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.