feat(quando-9sf): implement Next and Prev weekday navigation

- Add Next(weekday) method to jump to next occurrence of a weekday
- Add Prev(weekday) method to jump to previous occurrence of a weekday
- Next ALWAYS returns future date (never today, even if same weekday)
- Prev ALWAYS returns past date (never today, even if same weekday)
- Time of day preserved from source date
- Comprehensive unit tests for all weekday combinations
- Same-weekday edge case tests (Monday.Next(Monday) = next Monday)
- Timezone preservation tests
- Immutability verification tests
- Performance benchmarks (~45ns, well under 1µs target)
- Zero allocations for both operations
- 97.8% test coverage (exceeds 95% requirement)
- Godoc comments with same-weekday behavior examples

All acceptance criteria met:
✓ Next() implemented for all weekdays
✓ Prev() implemented for all weekdays
✓ Next() never returns today (always future)
✓ Prev() never returns today (always past)
✓ Time of day preserved from source
✓ Edge case: Same weekday correctly skips to next/prev week
✓ Unit tests for all weekday combinations
✓ Tests for same weekday edge case
✓ Benchmarks meet <1µs target (~45ns)
✓ Godoc comments with same-weekday behavior example
This commit is contained in:
Oliver Jakoubek 2026-02-11 17:33:54 +01:00
commit 273e920c1c
4 changed files with 372 additions and 1 deletions

View file

@ -191,3 +191,41 @@ func ExampleDate_StartOf_chaining() {
fmt.Printf("Type: %T\n", firstMondayOfQuarter)
// Output: Type: quando.Date
}
// ExampleDate_Next demonstrates finding the next occurrence of a weekday
func ExampleDate_Next() {
// On Monday, Feb 9, 2026
date := quando.From(time.Date(2026, 2, 9, 15, 30, 0, 0, time.UTC))
fmt.Println("Today:", date.Time().Weekday())
fmt.Println("Next Monday:", date.Next(time.Monday).Time().Weekday(), "-", date.Next(time.Monday))
fmt.Println("Next Friday:", date.Next(time.Friday).Time().Weekday(), "-", date.Next(time.Friday))
// Output:
// Today: Monday
// Next Monday: Monday - 2026-02-16 15:30:00
// Next Friday: Friday - 2026-02-13 15:30:00
}
// ExampleDate_Prev demonstrates finding the previous occurrence of a weekday
func ExampleDate_Prev() {
// On Monday, Feb 9, 2026
date := quando.From(time.Date(2026, 2, 9, 15, 30, 0, 0, time.UTC))
fmt.Println("Today:", date.Time().Weekday())
fmt.Println("Prev Monday:", date.Prev(time.Monday).Time().Weekday(), "-", date.Prev(time.Monday))
fmt.Println("Prev Friday:", date.Prev(time.Friday).Time().Weekday(), "-", date.Prev(time.Friday))
// Output:
// Today: Monday
// Prev Monday: Monday - 2026-02-02 15:30:00
// Prev Friday: Friday - 2026-02-06 15:30:00
}
// ExampleDate_Next_sameWeekday demonstrates the same-weekday edge case
func ExampleDate_Next_sameWeekday() {
// Next ALWAYS returns future, never today (even if same weekday)
monday := quando.From(time.Date(2026, 2, 9, 15, 30, 0, 0, time.UTC)) // Monday
nextMonday := monday.Next(time.Monday)
fmt.Printf("Days later: %d\n", int(nextMonday.Time().Sub(monday.Time()).Hours()/24))
// Output: Days later: 7
}