Skip to content

Replace max sleep hours with earliest reasonable bedtime#20

Merged
gsbernstein merged 8 commits into
masterfrom
cursor/earliest-bedtime-migration-023c
Jul 5, 2026
Merged

Replace max sleep hours with earliest reasonable bedtime#20
gsbernstein merged 8 commits into
masterfrom
cursor/earliest-bedtime-migration-023c

Conversation

@gsbernstein

@gsbernstein gsbernstein commented Jun 30, 2026

Copy link
Copy Markdown
Owner

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 UserPreferences model with only earliestReasonableBedtime (no legacy maxSleepHoursPerNight / minSleepHoursPerNight). All users are already on the new setting.

Changes

  • UserPreferencesearliestReasonableBedtime + effectiveMaxSleepHours
  • SettingsView — earliest bedtime picker with derived max-hours helper text
  • ViewModel — drops min-sleep parameter; ahead-of-goal nights recommend at least the sleep goal
  • ContentView — uses effectiveMaxSleepHours

Note

Separate from sleep insights (#14). If both land, wire effectiveMaxSleepHours into the insights engine in ContentView.

Open in Web Open in Cursor 

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 earliestReasonableBedtime in UserPreferences and derives effectiveMaxSleepHours from 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.

Comment thread Bedtime/Bedtime/Models/UserPreferences.swift Outdated
Comment thread Bedtime/Bedtime/Models/ViewModel.swift

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 maxSleepHours is explicitly DST-aware, the bedtime calculation should also be anchored to the next actual wake date; subtracting from the stored wakeTime date (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)

Comment thread Bedtime/Bedtime/Models/ViewModel.swift Outdated
Comment thread Bedtime/Bedtime/Models/UserPreferences.swift Outdated
Comment thread Bedtime/Bedtime/Models/UserPreferences.swift Outdated
@gsbernstein gsbernstein marked this pull request as ready for review July 5, 2026 20:54
@gsbernstein gsbernstein merged commit 85d8d81 into master Jul 5, 2026
@gsbernstein gsbernstein deleted the cursor/earliest-bedtime-migration-023c branch July 5, 2026 20:54
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.

3 participants