Skip to content

fix(timeutil): keep recurrence iterator index aligned with timestamp - #5556

Closed
pcbeingused333 wants to merge 1 commit into
openmeterio:mainfrom
pcbeingused333:fix/c3836-recurrence-iterator
Closed

pcbeingused333 wants to merge 1 commit into
openmeterio:mainfrom
pcbeingused333:fix/c3836-recurrence-iterator

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5521

The inclusive recurrence searches advance the iteration index before checking whether the candidate crosses the query time. When that candidate is rejected, the returned timestamp still belongs to the previous index. Navigating from the iterator then repeats or skips an occurrence.

Restore the index when rejecting a candidate in each affected search. This keeps the timestamp and index aligned without changing which initial occurrence is selected.

Regression coverage checks monthly recurrences with past and future anchors, both boundary modes, queries on and between occurrences, and two subsequent steps in each direction.

Validation: go test ./pkg/timeutil -count=1.

This change was prepared with AI assistance.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

Keeps recurrence iterator indices aligned with their timestamps after a search rejects a candidate.

  • Recurrence searches keep iterator steps matched to their returned time.

Reviews (1) · Last reviewed commit: "fix(timeutil): keep recurrence iterator ..." · Reviewed by Greptile

Summary by CodeRabbit

  • Bug Fixes
    • Corrected recurrence iterator navigation so iteration counts remain aligned with the dates returned when moving forward or backward, including around boundary times.
  • Tests
    • Added coverage for monthly recurrence navigation across inclusive and exclusive boundaries and different starting points.

@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 17, 2026 09:44
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The recurrence iterator now keeps its iteration index aligned with its returned timestamp when a search rejects a candidate. New monthly recurrence tests cover initialization and navigation across boundary modes and query times.

Changes: Recurrence iterator navigation

Layer / File(s) Summary
Restore index and verify navigation
pkg/timeutil/recurrence.go, pkg/timeutil/recurrence_test.go
Both search paths restore the iteration index when a candidate falls outside the query boundary. New tests check the starting month and two successive steps in each direction.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: turip, tothandras, galexihu

Merge Risk: Minimal · up to 7b4b8

This change keeps the recurrence iterator's position aligned with its returned timestamp, so stepping forward or backward no longer repeats or skips an occurrence. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the fix (keeping the recurrence iterator index aligned with the timestamp) in the pkg/timeutil recurrence code. The raw summary and PR objectives both describe this exact change: resto…
Linked Issues check Passed [#5521] The issue asks for the backwards-loop paths in IterateFromNextAfter and IterateFromPrevBefore to keep iteration and At aligned. The diff at pkg/timeutil/recurrence.go adds ic += 1 before the…
Out of Scope Changes check Passed The code change is two added lines in pkg/timeutil/recurrence.go, one per affected backwards-loop path. The test file adds a navigation test for monthly recurrences, which supports the linked issue. T…
Full details: Title check

Explanation

The title names the fix (keeping the recurrence iterator index aligned with the timestamp) in the pkg/timeutil recurrence code. The raw summary and PR objectives both describe this exact change: restoring the iteration index when a candidate is rejected in IterateFromNextAfter and IterateFromPrevBefore. The title is concise, specific, and conventional.

Full details: Linked Issues check

Explanation

[#5521] The issue asks for the backwards-loop paths in IterateFromNextAfter and IterateFromPrevBefore to keep iteration and At aligned. The diff at pkg/timeutil/recurrence.go adds ic += 1 before the break in the future-anchor loop of iterateFromNextAfterInclusive (the v.Before(t) check). It adds ic -= 1 before the break in the past-anchor loop of iterateFromPrevBeforeInclusive (the v.After(t) check). In both paths, res holds the instant for the restored index, so Next() and Prev() recompute the same instant the caller already holds. The other loop branches already update res and ic together, so they need no change. The issue's acceptance criterion for chained-iteration tests is addressed by the new TestRecurrenceIteratorNavigation in pkg/timeutil/recurrence_test.go, per the change summary. I did not read the test file hunks directly, so the test coverage verdict rests on the summary. No non-coding requirement applies.

Full details: Out of Scope Changes check

Explanation

The code change is two added lines in pkg/timeutil/recurrence.go, one per affected backwards-loop path. The test file adds a navigation test for monthly recurrences, which supports the linked issue. The PR description and the PR objectives both state that no grant-balance change is made. The diff contains no unrelated edits, so no out-of-scope changes were found.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f305c47 and 7b4b8eb.

Files selected for processing: 2

  • pkg/timeutil/recurrence.go
  • pkg/timeutil/recurrence_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Closing this as superseded: main has since rewritten recurrence.go (#5590) and the functions this PR patched no longer exist, so it no longer applies. Thanks for the reviews!

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.

RecurrenceIterator: iteration and At name different instants when the anchor is in the future, so Next() repeats or skips

1 participant