Drop support for standalone "L" in CronExpression
This commit removes support for a standalone "L" in the day-of-week of a cron expression, which used a locale-dependent API to determine what the last day of the week is (Saturday or Sunday ?). Alternatively, we could have implement this in the exact way as Quartz has done (i.e. treat the "L" like "SAT"), but we opted not to do that, as having an explicit SAT or SUN is much clearer.
This commit is contained in:
@@ -121,9 +121,7 @@ public final class CronExpression {
|
||||
* </li>
|
||||
* <li>
|
||||
* In the "day of week" field, {@code L} stands for "the last day of the
|
||||
* week", and uses the
|
||||
* {@linkplain java.util.Locale#getDefault() system default locale}
|
||||
* to determine which day that is (i.e. Sunday or Saturday).
|
||||
* week".
|
||||
* If prefixed by a number or three-letter name (i.e. {@code dL} or
|
||||
* {@code DDDL}), it means "the last day of week {@code d} (or {@code DDD})
|
||||
* in the month".
|
||||
@@ -158,7 +156,6 @@ public final class CronExpression {
|
||||
* <li>{@code "0 0 0 L-3 * *"} = third-to-last day of the month at midnight</li>
|
||||
* <li>{@code "0 0 0 1W * *"} = first weekday of the month at midnight</li>
|
||||
* <li>{@code "0 0 0 LW * *"} = last weekday of the month at midnight</li>
|
||||
* <li>{@code "0 0 0 * * L"} = last day of the week at midnight</li>
|
||||
* <li>{@code "0 0 0 * * 5L"} = last Friday of the month at midnight</li>
|
||||
* <li>{@code "0 0 0 * * THUL"} = last Thursday of the month at midnight</li>
|
||||
* <li>{@code "0 0 0 ? * 5#2"} = the second Friday in the month at midnight</li>
|
||||
|
||||
@@ -23,9 +23,6 @@ import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.Temporal;
|
||||
import java.time.temporal.TemporalAdjuster;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.time.temporal.TemporalField;
|
||||
import java.time.temporal.WeekFields;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -140,8 +137,8 @@ final class QuartzCronField extends CronField {
|
||||
}
|
||||
else {
|
||||
TemporalAdjuster adjuster;
|
||||
if (idx == 0) { // "L"
|
||||
adjuster = lastDayOfWeek(Locale.getDefault());
|
||||
if (idx == 0) {
|
||||
throw new IllegalArgumentException("No day-of-week before 'L' in '" + value + "'");
|
||||
}
|
||||
else { // "[0-7]L"
|
||||
DayOfWeek dayOfWeek = parseDayOfWeek(value.substring(0, idx));
|
||||
@@ -196,18 +193,6 @@ final class QuartzCronField extends CronField {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a temporal adjuster that finds the last day-of-week, depending
|
||||
* on the given locale.
|
||||
* @param locale the locale to base the last day calculation on
|
||||
* @return the last day-of-week adjuster
|
||||
*/
|
||||
private static TemporalAdjuster lastDayOfWeek(Locale locale) {
|
||||
Assert.notNull(locale, "Locale must not be null");
|
||||
TemporalField dayOfWeek = WeekFields.of(locale).dayOfWeek();
|
||||
return temporal -> temporal.with(dayOfWeek, 7);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a temporal adjuster that finds the weekday nearest to the given
|
||||
* day-of-month. If {@code dayOfMonth} falls on a Saturday, the date is
|
||||
|
||||
Reference in New Issue
Block a user