Skip to content

Exclude incomplete current day from sleep bank before wake time#25

Draft
gsbernstein wants to merge 1 commit into
cursor/sleep-bank-insights-023cfrom
cursor/exclude-incomplete-sleep-day-8b42
Draft

Exclude incomplete current day from sleep bank before wake time#25
gsbernstein wants to merge 1 commit into
cursor/sleep-bank-insights-023cfrom
cursor/exclude-incomplete-sleep-day-8b42

Conversation

@gsbernstein

Copy link
Copy Markdown
Owner

Problem

Right after midnight, the sleep bank lookback window shifts to include the new calendar day. If that day has no sleep data yet and it's still before the user's wake time, the window drops an older day and can incorrectly extend insight messaging — e.g. "ahead over the last 5 days" instead of 4.

Fix

Add SleepWindow.effectiveSleepBankEndDate, which anchors the sleep bank end to end of yesterday when:

  • today has no recorded sleep, and
  • the current time is before today's wake time

calculateSleepBank and the sleep insights engine now use this effective end date, keeping lookback windows stable until the user has actually woken up for the day.

Notes

This branch is based on the sleep bank insights work (cursor/sleep-bank-insights-023c) since that's where the "ahead over the last N days" messaging lives. Cannot be built or tested in the Cloud Agent environment (macOS/Xcode only).

Open in Web Open in Cursor 

When the calendar day has no sleep data yet and it is still before the
user's wake time, anchor sleep bank and insight lookback windows to end
of yesterday. This prevents the window from shifting at midnight and
incorrectly extending the ahead/behind day count.

Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
@gsbernstein gsbernstein changed the base branch from master to cursor/sleep-bank-insights-023c July 10, 2026 07:15
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.

2 participants