Replace max sleep hours with earliest reasonable bedtime#20
Merged
Conversation
Adds earliest reasonable bedtime setting derived from wake time, migrates from the legacy max-hours value, and recovers from incompatible SwiftData stores on startup. Removes the minimum sleep hours setting and floors ahead-of-goal recommendations at the sleep goal instead. Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
Everyone is on earliest reasonable bedtime now. Removes maxSleepHoursPerNight, minSleepHoursPerNight, runtime migration, and store-deletion recovery from ModelContainer setup. Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR replaces the “max sleep hours per night” limit with an “earliest reasonable bedtime” time picker, deriving the maximum allowed sleep window from the user’s wake time, and removes the minimum-sleep setting from the recommendation logic.
Changes:
- Introduces
earliestReasonableBedtimeinUserPreferencesand deriveseffectiveMaxSleepHoursfrom wake time. - Updates Settings UI to use a time-of-day picker and display the derived maximum sleep window.
- Simplifies bedtime recommendation inputs by removing the min-sleep parameter and flooring “ahead” recommendations at the sleep goal.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Bedtime/Bedtime/Views/SettingsView.swift | Replaces max/min sleep sliders with an earliest-bedtime picker and derived helper text. |
| Bedtime/Bedtime/Models/ViewModel.swift | Removes minSleepHours input and adjusts recommendation floor logic when ahead of goal. |
| Bedtime/Bedtime/Models/UserPreferences.swift | Removes legacy max/min fields; adds earliest bedtime and a derived max-sleep calculation helper. |
| Bedtime/Bedtime/ContentView.swift | Switches recommendation input from legacy max hours to effectiveMaxSleepHours. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
Bedtime/Bedtime/Models/ViewModel.swift:75
- Now that
maxSleepHoursis explicitly DST-aware, the bedtime calculation should also be anchored to the next actual wake date; subtracting from the storedwakeTimedate (which is effectively just a time-of-day) won’t account for DST transitions and can be off by an hour on those nights.
reason = "You're ahead of the game! Aim for at least \(String(format: "%.1f", sleepGoal)) hours tonight."
}
// Calculate recommended bedtime
let recommendedBedtime = calendar.date(byAdding: .minute, value: -Int(totalSleepNeeded * 60), to: wakeTime) ?? wakeTime.addingTimeInterval(-totalSleepNeeded * 60 * 60)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Replaces max sleep hours per night with earliest reasonable bedtime — a time-of-day picker that derives the longest allowed sleep window from wake time.
Also removes the minimum sleep hours setting. When you're ahead of your sleep goal, recommendations floor at your goal rather than encouraging a shorter night.
Schema
Clean
UserPreferencesmodel with onlyearliestReasonableBedtime(no legacymaxSleepHoursPerNight/minSleepHoursPerNight). All users are already on the new setting.Changes
UserPreferences—earliestReasonableBedtime+effectiveMaxSleepHoursSettingsView— earliest bedtime picker with derived max-hours helper textViewModel— drops min-sleep parameter; ahead-of-goal nights recommend at least the sleep goalContentView— useseffectiveMaxSleepHoursNote
Separate from sleep insights (#14). If both land, wire
effectiveMaxSleepHoursinto the insights engine inContentView.