Skip to content

feat(views): lazy calendar-view iterators (days/weeks)#6

Merged
AriajSarkar merged 14 commits intomainfrom
feat/calendar-view-iterators
Mar 22, 2026
Merged

feat(views): lazy calendar-view iterators (days/weeks)#6
AriajSarkar merged 14 commits intomainfrom
feat/calendar-view-iterators

Conversation

@AriajSarkar
Copy link
Owner

@AriajSarkar AriajSarkar commented Mar 18, 2026

Summary

Add lazy DayIterator and WeekIterator to Calendar that yield pre-bucketed, owned event views — making it trivial to plug eventix into Rust UI frameworks (Yew, Leptos, Dioxus) for calendar rendering.

Closes #5


New Public API

// Forward day iteration — each DayView has events pre-bucketed
for day in cal.days(start).take(30) {
    let day = day?;
    println!("{}: {} events", day.date(), day.event_count());
    for event in day.events() {
        println!("  {} at {}", event.title(), event.occurrence_time);
    }
}

// Week iteration — each WeekView contains 7 contiguous DayViews (Mon–Sun)
for week in cal.weeks(start).take(4) {
    let week = week?;
    println!("Week of {}: {} events", week.start_date(), week.event_count());
}

// Backward iteration for scrolling into the past
let previous_days = cal.days_back(today).take(30);

// Jump to a specific date (resume after scroll)
let mut iter = cal.days(start);
iter.skip_to(target_date);

New Types

Type Description
DayView A single calendar day with all active intersecting events pre-bucketed
WeekView Seven contiguous DayViews (Monday–Sunday)
OwnedEventOccurrence Owned snapshot of an occurrence — no lifetime ties to Calendar
DayIterator Lazy, fallible iterator over days (Item = Result)
WeekIterator Lazy, fallible iterator over ISO weeks (Item = Result)

Key Design Decisions

  • Owned data: DayView / OwnedEventOccurrence own their event data (Clone + PartialEq + Eq + Hash + Ord), so views can be freely moved into UI component props without lifetime issues.
  • Fallible iteration: Iterators yield Result instead of silently stopping on errors — callers get full diagnostic info.
  • Timezone-aware day boundaries: Day windows computed via local_day_window() respect DST transitions (a 25-hour day on fall-back is handled correctly).
  • Intersection-based bucketing: Overnight/multi-day events appear on every day they span, not just the start day.
  • ExactSizeIterator + FusedIterator: Both iterators formally advertise their exact remaining length and fused exhaustion.
  • skip_to(date): Lets consumers jump the cursor for "load more" / infinite-scroll UIs.
  • Additive only: No breaking changes to any existing API.

Framework Compatibility

Verified compatible with the prop/signal requirements of:

  • Yew — Clone + PartialEq ✅
  • Leptos — Clone + Send + Sync + 'static ✅ (NaiveDate is a perfect key)
  • Dioxus — Clone + PartialEq ✅

Files Changed (12 files, +1210 / -68)

File Change
src/views.rs [NEW] Core module — all view types, iterators, helpers, 16 unit tests
ests/calendar_view_tests.rs [NEW] Integration tests — overnight events, DST boundary, backward weeks, cancelled exclusion
examples/calendar_views.rs [NEW] Runnable example demonstrating day/week iteration
src/calendar.rs Added days(), days_back(), weeks(), weeks_back() methods
src/event.rs Added PartialOrd + Ord + Hash to EventStatus
src/timezone.rs Extracted
esolve_local(), added local_day_window()
src/recurrence.rs Refactored to use shared
esolve_local from timezone module
src/lib.rs Added �iews module, re-exports, NaiveDate re-export
README.md Added Calendar Views section with usage examples
CHANGELOG.md v0.5.0 entry
Cargo.toml Version bump to 0.5.0
TODO.md Marked feature as complete

Verification

  • cargo test — 112 tests pass
  • cargo test --doc — all doc tests pass
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo run --example calendar_views — runs correctly
  • Three rounds of code review (bugs fixed, edge cases handled, framework compatibility verified)

- introduce `Calendar::days/days_back` and `weeks/weeks_back` with `DayView`/`WeekView`
- add owned occurrence model and fallible iterators yielding `Result` items
- switch day-boundary logic to half-open local windows for date checks and event queries
- export new `views` module, add example/tests, and bump crate version to `0.5.0`
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@AriajSarkar AriajSarkar changed the title feat(views): lazy calendar-view iterators (days/weeks) — closes #5 feat(views): lazy calendar-view iterators (days/weeks) Mar 18, 2026
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- cover Event::occurs_on for matching and non-matching days
- verify week all_events ordering across days
- add edge-case checks for inclusive day end and week boundary helpers
- validate invalid full-week start returns zero remaining weeks
- Use checked arithmetic when stepping back from nonexistent local times
- Add regression test for the New York spring-forward gap
… for gaps between events. Now it correctly tracks which event precedes each gap.

- schedule.ics added to Cargo.toml exclude — Prevents a stray test file from shipping in the published crate.
…breaking changes, and fixes

- Added calendar view iterators and owned view models for better UI rendering.
- Introduced integration and unit tests for improved coverage.
- Documented changes in serialization behavior and validation error messages.
- Fixed issues with week day advancement and example imports in README.
- Enhanced `to_json` method to provide clearer error messages during serialization.
- Updated `from_json` method to ignore invalid timezone fields at the top level while enforcing validation for event-level timezones.
- Refactored various sections for improved readability and consistency in error handling.
- Added tests to ensure proper handling of missing events and malformed JSON inputs.
…cross examples

- Enhanced rustfmt configuration for better readability and consistency.
- Refactored example files to consolidate print statements into single lines for improved clarity.
- Minor adjustments in performance benchmarks for cleaner code structure.
@AriajSarkar AriajSarkar merged commit 9e60e68 into main Mar 22, 2026
8 checks passed
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.

feat: Lazy calendar-view iterators (days() / weeks())

1 participant