Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.anderswisch:cron-expression:'
}
dependencies {
implementation("com.github.anderswisch:cron-expression:")
}
<dependency>
<groupId>com.github.anderswisch</groupId>
<artifactId>cron-expression</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.anderswisch" % "cron-expression" % ""
:dependencies [[com.github.anderswisch/cron-expression ""]]
This project contains code to parse cron
expressions and build corresponding Java objects. It provides a small
interface for checking whether a cron
expression matches a java.time.ZonedDateTime
object. It provides code for
integrating with java.util.concurrent
, though using this is optional and it might be more straightforward to roll
your own.
It might come in handy if you're already using (or don't mind using) Java8, Guava,
want to handle cron
expressions, and don't want a full-blown scheduling library like Quartz.
1-10
which is equivalent to 1,2,3,4,5,6,7,8,9,10
1-10/2
which is equivalent to 1,3,5,7,9
*/5
Alias | Description | Equivalent
----------|-----------------------------------------------------------------------|-------------
@reboot | Run at startup |
@yearly | Run once a year at midnight in the morning of January 1 | 0 0 1 1 *
@annually | (same as @yearly) |
@monthly | Run once a month at midnight in the morning of the first of the month | 0 0 1 * *
@weekly | Run once a week at midnight in the morning of Sunday | 0 0 * * 0
@daily | Run once a day at midnight | 0 0 * * *
@midnight | (same as @daily) |
@hourly | Run once an hour at the beginning of the hour | 0 * * * *
0 0 * * 1#2,5#3
(at midnight on the second Monday and third Friday of every month)0 0 * * 1L,5L
(at midnight on the last Friday and last Monday of every month)java.util.concurrent
cron
expressions as immutable objectsZonedDateTime time = ZonedDateTime.now().withDayOfYear(1).truncatedTo(ChronoUnit.DAYS);
assertTrue(CronExpression.parse("0 0 1 1 *").matches(time));
assertTrue(CronExpression.parse("@yearly").matches(time));
assertTrue(CronExpression.parse("@annually").matches(time));
assertTrue(CronExpression.yearly().matches(time));
CronExpression expression = CronExpression.parser()
.withSecondsField(true)
.withOneBasedDayOfWeek(true)
.allowBothDayFields(false)
.parse("0 15 10 L * ?");
ZonedDateTime time = ZonedDateTime.now().truncatedTo(ChronoUnit.DAYS)
.withYear(2013)
.withMonth(1)
.withDayOfMonth(31)
.withHour(10)
.withMinute(15);
assertTrue(expression.matches(time));
You can find more examples in the unit tests.