Skip to content

Add CalculateCyclesInWindow function#4

Merged
TyostoKarry merged 1 commit into
mainfrom
add-calculation-logic-for-set-window
Mar 9, 2026
Merged

Add CalculateCyclesInWindow function#4
TyostoKarry merged 1 commit into
mainfrom
add-calculation-logic-for-set-window

Conversation

@TyostoKarry

Copy link
Copy Markdown
Owner

Adds window-based cycle calculation to the core logic, returning both complete cycle count and remaining overflow duration.

Changes
internal/cycle/cycle.go_

  • CalculateCyclesInWindow — calculates complete cycles and remaining overflow duration between two times, handles next-day wake by adding 24h when to is not after from

internal/cycle/cycle_test.go

  • Tests covering exact cycles, with/without buffer, next-day wake, overflow only, midnight boundary, and same from/to edge case

Notes

  • Returns (int, time.Duration) — overflow is intentionally exposed for use by the output layer to indicate how far into a partial cycle the wake time falls
  • Same from/to input results in a 24h window (16 cycles) — this should be guarded against at the CLI layer

Add CalculateCyclesInWindow to calculate the number of complete sleep cycles and remaining overflow duration within a given time window. Handles next-day wake times by adding 24h when to is not after from. Add tests covering buffer, overflow, next-day wake, midnight boundary, and same from/to edge cases.
@TyostoKarry TyostoKarry self-assigned this Mar 9, 2026
@TyostoKarry TyostoKarry merged commit 38be142 into main Mar 9, 2026
2 checks passed
@TyostoKarry TyostoKarry deleted the add-calculation-logic-for-set-window branch March 9, 2026 15:48
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.

1 participant