jmrozanec / jmrozanec/cron-utils

How to create a cron expression for every N hours between time X to time Y

Open
#609 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.2k
Forks
272
PR merge metrics
No merged PRs in 30d

Description

Hello I was able to create an expression for **At 1 minutes past the hour, every 8 hours, between day 1 and 3 of the month, only in 2023**

```
public static void main(String[] args) {
CronBuilder builder = CronBuilder.cron(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
Cron cron = builder
.withYear(on(2023))
.withDoM(between(1, 3))
.withMonth(always())
.withDoW(questionMark())
.withHour(every(8))
.withMinute(on(1))
.withSecond(on(0))
.instance();
System.out.println(cron.asString());
}
````

Which produced this output
![Screenshot from 2023-11-04 11-37-56](https://github.com/jmrozanec/cron-utils/assets/29277048/ba9e8fe9-f040-4199-a1ce-488d80fa851f)

But I wanted to do more by specifying the hours between 06:00 AM to 11:59 PM. Something like this
![Screenshot from 2023-11-04 11-37-41](https://github.com/jmrozanec/cron-utils/assets/29277048/2f500172-6abd-458b-b5cd-c2416a4857f7)
Thanks for any help or suggestion

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.