Skip to content

Commit 585fae3

Browse files
committed
#501: Support new cron definitions for Spring 5.3+
1 parent f56c20c commit 585fae3

1 file changed

Lines changed: 79 additions & 2 deletions

File tree

src/main/java/com/cronutils/model/definition/CronDefinitionBuilder.java

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ private static CronDefinition quartz() {
332332
}
333333

334334
/**
335-
* Creates CronDefinition instance matching Spring specification.
335+
* Creates CronDefinition instance matching Spring (v5.2 and below) specification.
336336
*
337337
* <p>The cron expression is expected to be a string comprised of 6
338338
* fields separated by white space. Fields can contain any of the allowed
@@ -384,7 +384,7 @@ private static CronDefinition quartz() {
384384
* </tr>
385385
* </table>
386386
*
387-
* <p>Thus in general Spring cron expressions are as follows:
387+
* <p>Thus in general Spring cron expressions are as follows (up to version 5.2):
388388
*
389389
* <p>S M H DoM M DoW
390390
*
@@ -402,6 +402,83 @@ private static CronDefinition spring() {
402402
.instance();
403403
}
404404

405+
/**
406+
* Creates CronDefinition instance matching Spring (v5.2 onwards) specification.
407+
* https://spring.io/blog/2020/11/10/new-in-spring-5-3-improved-cron-expressions
408+
*
409+
* <p>The cron expression is expected to be a string comprised of 6
410+
* fields separated by white space. Fields can contain any of the allowed
411+
* values, along with various combinations of the allowed special characters
412+
* for that field. The fields are as follows:
413+
*
414+
* <table style="width:100%">
415+
* <tr>
416+
* <th>Field Name</th>
417+
* <th>Mandatory</th>
418+
* <th>Allowed Values</th>
419+
* <th>Allowed Special Characters</th>
420+
* </tr>
421+
* <tr>
422+
* <td>Seconds</td>
423+
* <td>YES</td>
424+
* <td>0-59</td>
425+
* <td>* , - /</td>
426+
* </tr>
427+
* <tr>
428+
* <td>Minutes</td>
429+
* <td>YES</td>
430+
* <td>0-59</td>
431+
* <td>* , - /</td>
432+
* </tr>
433+
* <tr>
434+
* <td>Hours</td>
435+
* <td>YES</td>
436+
* <td>0-23</td>
437+
* <td>* , - /</td>
438+
* </tr>
439+
* <tr>
440+
* <td>Day of month</td>
441+
* <td>YES</td>
442+
* <td>1-31</td>
443+
* <td>* ? , - / L W</td>
444+
* </tr>
445+
* <tr>
446+
* <td>Month</td>
447+
* <td>YES</td>
448+
* <td>1-12 or JAN-DEC</td>
449+
* <td>* , -</td>
450+
* </tr>
451+
* <tr>
452+
* <td>Day of week</td>
453+
* <td>YES</td>
454+
* <td>0-7 or SUN-SAT</td>
455+
* <td>* ? , - / L #</td>
456+
* </tr>
457+
* </table>
458+
*
459+
* <p>Thus in general Spring cron expressions are as follows (from version 5.3 onwards):
460+
*
461+
* <p>S M H DoM M DoW
462+
*
463+
* @return {@link CronDefinition} instance, never {@code null}
464+
*/
465+
private static CronDefinition spring53() {
466+
return CronDefinitionBuilder.defineCron()
467+
.withSeconds().withValidRange(0, 59).withStrictRange().and()
468+
.withMinutes().withValidRange(0, 59).withStrictRange().and()
469+
.withHours().withValidRange(0, 23).withStrictRange().and()
470+
.withDayOfMonth().withValidRange(1, 31).supportsL().supportsW().supportsLW().supportsQuestionMark().and()
471+
.withMonth().withValidRange(1, 12).and()
472+
.withDayOfWeek().withValidRange(0, 7).withMondayDoWValue(1).withIntMapping(7,0)
473+
.supportsHash().supportsL().supportsQuestionMark().and()
474+
.withSupportedNicknameYearly().withSupportedNicknameAnnually()
475+
.withSupportedNicknameMonthly()
476+
.withSupportedNicknameWeekly()
477+
.withSupportedNicknameDaily().withSupportedNicknameMidnight()
478+
.withSupportedNicknameHourly()
479+
.instance();
480+
}
481+
405482
/**
406483
* Creates CronDefinition instance matching unix crontab specification.
407484
*

0 commit comments

Comments
 (0)