Due to general lack of time, and limited interest, I am archiving this repository. No further versions will be updated on Maven. If you require customization you should include the cron
and utils
folders directly into your project.
A Java library that converts cron expressions into human readable descriptions. Adapted from original work by Brady Holt (https://github.com/bradymholt/cron-expression-descriptor)
Licensed under the MIT license
Add the following dependency to your pom.xml:
<dependency>
<groupId>it.burning</groupId>
<artifactId>cron-expression-descriptor</artifactId>
<version>1.2.10</version>
</dependency>
Add the repositories and dependency to your gradle.build script:
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
dependencies {
implementation "it.burning:cron-expression-descriptor:1.2.10"
}
A CronExpressionParser.Options
object can be passed to CronExpressionDescriptor.getDescription()
. The following options are available:
SUNDAY
for the Day Of Weekstring locale - The locale to use (Default: current system locale)
Example usage with default options:
CronExpressionDescriptor.getDescription("0 0 12 * * ?");
> "At 12:00, every day"
Example usage with custom options:
CronExpressionDescriptor.getDescription("0 0 12 * * ?",new Options(){{
setLocale("it");
setUse24HourTimeFormat(false);
}});
>"Alle 12:00 PM, ogni giorno"
Example usage for JEE Timer expressions [ Available Since Version 1.2.6+ ] (https://docs.oracle.com/javaee/7/tutorial/ejb-basicexamples004.htm):
CronExpressionDescriptor.getDescription("0 0 13 * * 0",new Options(){{
setUseJavaEeScheduleExpression(true);
}});
>"At 13:00, only on Sunday"
CronExpressionDescriptor.getDescription("0 0 13 * * 7",new Options(){{
setUseJavaEeScheduleExpression(true);
}});
>"At 13:00, only on Sunday"
CronExpressionDescriptor.getDescription("0 0 13 * * 1",new Options(){{
setUseJavaEeScheduleExpression(true);
}});
>"At 13:00, only on Monday"
Please Note: Default options are cached internally, but if you want to use a custom Options set it is advisable to instantiate it only once and reuse it on every subsequent call to avoid useless allocation.
The following language translations are available.
en
(Brady Holt)bg
(Angel Gospodinov)zh-CN
(Star Peng)zh-TW
(Ricky Chiang)da
(Rasmus Melchior Jacobsen)nl
(TotalMace)fi
(Mikael Rosenberg)fr
(Arnaud TAMAILLON)de
(Michael Schuler)it
(Luca Vignaroli)ja
(Alin Sarivan)ko
(Ion Mincu)nb
(Siarhei Khalipski)pl
(foka)pt
(Miguel Guimarães)pt-BR
(Renato Lima)ro
(Illegitimis)ru
(LbISS)sl-SI
(Jani Bevk)es
(Ivan Santos)es-MX
(Ion Mincu)sv
(roobin)tr
(Mustafa SADEDİL)uk
(Taras)vi
(Duong Van Minh)If you want to manually set a default Locale for the descripion, to be used for all subsequent calls to " getDescription()" you can use the static method "setDefaultLocale()" by passing it the language identifier:
CronExpressionDescriptor.setDefaultLocale("it");
CronExpressionDescriptor.getDescription("0-10 11 * * *");
> "Alle 12:00, ogni giorno"
And you can revert at any time to the default Locale:
For Version 1.2.3+
CronExpressionDescriptor.setDefaultLocale();
CronExpressionDescriptor.getDescription("0-10 11 * * *");
> "At 12:00, every day"
Up until Version 1.2.2
CronExpressionDescriptor.setDefaultLocale(null);
CronExpressionDescriptor.getDescription("0-10 11 * * *");
> "At 12:00, every day"