Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CronExpression fails to calculate next execution on the day of daylight saving time #28044

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -260,7 +260,7 @@ public <T extends Temporal & Comparable<? super T>> T elapseUntil(T temporal, in
* Roll forward the give temporal until it reaches the next higher
* order field. Calling this method is equivalent to calling
* {@link #elapseUntil(Temporal, int)} with goal set to the
* minimum value of this field's range.
* minimum value of this field's range, except for daylight saving.
* @param temporal the temporal to roll forward
* @param <T> the type of temporal
* @return the rolled forward temporal
Expand All @@ -269,7 +269,12 @@ public <T extends Temporal & Comparable<? super T>> T rollForward(T temporal) {
int current = get(temporal);
ValueRange range = temporal.range(this.field);
long amount = range.getMaximum() - current + 1;
return this.field.getBaseUnit().addTo(temporal, amount);
T result = this.field.getBaseUnit().addTo(temporal, amount);
//adjust daylight saving
if (get(result) != range.getMinimum()) {
result = this.field.adjustInto(result,result.range(this.field).getMinimum());
}
return result;
}

/**
Expand Down
Expand Up @@ -1336,6 +1336,14 @@ public void daylightSaving() {
actual = cronExpression.next(last);
assertThat(actual).isNotNull();
assertThat(actual).isEqualTo(expected);

cronExpression = CronExpression.parse("0 5 0 * * *");

last = ZonedDateTime.parse("2021-03-28T01:00:00+01:00[Europe/Amsterdam]");
expected = ZonedDateTime.parse("2021-03-29T00:05+02:00[Europe/Amsterdam]");
actual = cronExpression.next(last);
assertThat(actual).isNotNull();
assertThat(actual).isEqualTo(expected);
}

@Test
Expand Down