You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(timeutil): keep recurrence iterator index aligned with timestamp - #5556
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.
Confidence 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.
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.
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.
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: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
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
[#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
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.
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.
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.


Confidence Score: 5/5
The PR appears safe to merge.Summary
Keeps recurrence iterator indices aligned with their timestamps after a search rejects a candidate.
Reviews (1) · Last reviewed commit: "fix(timeutil): keep recurrence iterator ..." · Reviewed by Greptile
Summary by CodeRabbit