Skip to content

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

Draft
gsbernstein wants to merge 10 commits into
masterfrom
cursor/exclude-incomplete-sleep-day-8b42
Draft

Exclude incomplete current day from sleep bank before wake time#25
gsbernstein wants to merge 10 commits into
masterfrom
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 

cursoragent and others added 10 commits July 5, 2026 14:24
Introduces SleepInsightsEngine that scans 3–14 day lookbacks, picks
congratulation and motivator windows, and builds narrative copy with
human-readable catch-up fractions. Shows a Sleep Insight card below the
sleep balance card and omits duplicate recommendation footer text when
the insight covers uncatchable debt.

Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
Introduce a shared CardHeader component with a fixed-width, center-aligned
icon column and uniform spacing so titles line up across Sleep Balance, Sleep
Insight, Tonight's Recommendation, and all other dashboard cards.

Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
Local minima excluded longer flattering spans when adding a day improved
the balance. Congratulations now uses the longest lookback still ahead.

Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
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
Base automatically changed from cursor/sleep-bank-insights-023c to master August 4, 2026 06:09
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