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:
@@ -24,14 +24,12 @@ import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.Temporal;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static java.time.DayOfWeek.FRIDAY;
|
||||
import static java.time.DayOfWeek.MONDAY;
|
||||
import static java.time.DayOfWeek.SATURDAY;
|
||||
import static java.time.DayOfWeek.SUNDAY;
|
||||
import static java.time.DayOfWeek.TUESDAY;
|
||||
import static java.time.DayOfWeek.WEDNESDAY;
|
||||
@@ -736,60 +734,6 @@ class CronExpressionTests {
|
||||
assertThat(actual).is(weekday);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quartzLastDayOfWeekFirstDayMonday() {
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
try {
|
||||
Locale.setDefault(Locale.UK);
|
||||
|
||||
CronExpression expression = CronExpression.parse("0 0 0 * * L");
|
||||
|
||||
LocalDateTime last = LocalDateTime.of(LocalDate.of(2008, 1, 4), LocalTime.now());
|
||||
LocalDateTime expected = LocalDateTime.of(2008, 1, 6, 0, 0);
|
||||
LocalDateTime actual = expression.next(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
assertThat(actual.getDayOfWeek()).isEqualTo(SUNDAY);
|
||||
|
||||
last = actual;
|
||||
expected = expected.plusWeeks(1);
|
||||
actual = expression.next(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
assertThat(actual.getDayOfWeek()).isEqualTo(SUNDAY);
|
||||
}
|
||||
finally {
|
||||
Locale.setDefault(defaultLocale);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quartzLastDayOfWeekFirstDaySunday() {
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
try {
|
||||
Locale.setDefault(Locale.US);
|
||||
|
||||
CronExpression expression = CronExpression.parse("0 0 0 * * L");
|
||||
|
||||
LocalDateTime last = LocalDateTime.of(LocalDate.of(2008, 1, 4), LocalTime.now());
|
||||
LocalDateTime expected = LocalDateTime.of(2008, 1, 5, 0, 0);
|
||||
LocalDateTime actual = expression.next(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
assertThat(actual.getDayOfWeek()).isEqualTo(SATURDAY);
|
||||
|
||||
last = actual;
|
||||
expected = expected.plusWeeks(1);
|
||||
actual = expression.next(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
assertThat(actual.getDayOfWeek()).isEqualTo(SATURDAY);
|
||||
}
|
||||
finally {
|
||||
Locale.setDefault(defaultLocale);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quartzLastDayOfWeekOffset() {
|
||||
// last Friday (5) of the month
|
||||
|
||||
@@ -18,12 +18,9 @@ package org.springframework.scheduling.support;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static java.time.DayOfWeek.SATURDAY;
|
||||
import static java.time.DayOfWeek.SUNDAY;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
@@ -62,48 +59,6 @@ class QuartzCronFieldTests {
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lastDayOfWeekFirstDayMonday() {
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
try {
|
||||
Locale.setDefault(Locale.UK);
|
||||
QuartzCronField field = QuartzCronField.parseDaysOfWeek("L");
|
||||
|
||||
LocalDate last = LocalDate.of(2020, 6, 16);
|
||||
LocalDate expected = LocalDate.of(2020, 6, 21);
|
||||
assertThat(field.nextOrSame(last)).isEqualTo(expected);
|
||||
|
||||
LocalDate actual = field.nextOrSame(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
assertThat(actual.getDayOfWeek()).isEqualTo(SUNDAY);
|
||||
}
|
||||
finally {
|
||||
Locale.setDefault(defaultLocale);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lastDayOfWeekFirstDaySunday() {
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
try {
|
||||
Locale.setDefault(Locale.US);
|
||||
QuartzCronField field = QuartzCronField.parseDaysOfWeek("L");
|
||||
|
||||
LocalDate last = LocalDate.of(2020, 6, 16);
|
||||
LocalDate expected = LocalDate.of(2020, 6, 20);
|
||||
assertThat(field.nextOrSame(last)).isEqualTo(expected);
|
||||
|
||||
LocalDate actual = field.nextOrSame(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
assertThat(actual.getDayOfWeek()).isEqualTo(SATURDAY);
|
||||
}
|
||||
finally {
|
||||
Locale.setDefault(defaultLocale);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void lastDayOfWeekOffset() {
|
||||
// last Thursday (4) of the month
|
||||
@@ -129,6 +84,7 @@ class QuartzCronFieldTests {
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> QuartzCronField.parseDaysOfWeek(""));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> QuartzCronField.parseDaysOfWeek("1"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> QuartzCronField.parseDaysOfWeek("L"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> QuartzCronField.parseDaysOfWeek("L1"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> QuartzCronField.parseDaysOfWeek("LL"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> QuartzCronField.parseDaysOfWeek("-4L"));
|
||||
|
||||
Reference in New Issue
Block a user