Skip to content

fix: wrap month start/interval across year (#692) - #722

Open
arimu1 wants to merge 1 commit into
jmrozanec:masterfrom
arimu1:fix/692-month-interval-wrap
Open

fix: wrap month start/interval across year (#692)#722
arimu1 wants to merge 1 commit into
jmrozanec:masterfrom
arimu1:fix/692-month-interval-wrap

Conversation

@arimu1

@arimu1 arimu1 commented Aug 8, 2026

Copy link
Copy Markdown

Summary

Fixes #692

ExecutionTime only returned the starting month for expressions like 10/3 (e.g. only October each year), skipping the rest of the every-N-months sequence (Jan/Apr/Jul).

Cause

EveryFieldValueGenerator for On(start)/period set from = start and to = field end. For months that yields only values ≥ start that fit in 1–12, so 10/3{10} only.

Fix

For the MONTH field with start/period (On + period), treat the progression as continuous across the year boundary using modular match:

floorMod(month - start, period) == 0

So 10/3{1, 4, 7, 10} (Oct, Jan, Apr, Jul). Other fields (hours, minutes, …) keep non-wrapping behavior (22/3 remains {22}).

Reproduction (now fixed)

CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
ExecutionTime et = ExecutionTime.forCron(parser.parse("0 0 0 15 10/3 ? *"));

et.nextExecution(ZonedDateTime.parse("2026-01-01T00:00:00Z"));
// → 2026-01-15 (was 2026-10-15)

et.getExecutionDates(
    ZonedDateTime.parse("2025-10-01T00:00:00Z"),
    ZonedDateTime.parse("2026-10-31T00:00:00Z"));
// → Oct 15 2025, Jan 15 2026, Apr 15 2026, Jul 15 2026, Oct 15 2026

Test plan

  • Issue692Test — next/last/getExecutionDates + sequence for 10/3
  • EveryFieldValueGeneratorTest — month wrap candidates; hours 22/3 still non-wrapping
  • Full suite: 810 tests, 0 failures (Temurin 21)

EveryFieldValueGenerator treated month "10/3" as only month 10
(from=start, to=12), so ExecutionTime skipped Jan/Apr/Jul.

For MONTH + On/period, match months with year wrap via floorMod
so 10/3 yields Oct, Jan, Apr, Jul. Non-month fields unchanged.

Fixes jmrozanec#692
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: ExecutionTime incorrectly skips month intervals e.g. "0 0 0 15 10/3 ? *"

1 participant