Skip to content
C.W.K.
Stream
Lesson 03 of 04 · published

Rolling Windows Are Inclusive

~10 min · rolling-window, date-arithmetic, queries, inclusive

Level 0Dry Nib
0 XP0/36 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete
"Name both ends of a window; “recent” is not a boundary."

What actually persists

A label such as “7 days” is ambiguous until the boundary is written. Inkwell means the selected local date plus the six preceding local dates. The 30-day view follows the same inclusive rule.

Views are queries

Compute the start date in calendar arithmetic and query start <= entry_date <= end. Store dates in canonical ISO form so lexical ordering matches calendar ordering.

What ambiguity costs

Using the previous seven dates excludes today. Using 168 hours makes daylight-saving transitions and time of day leak into a calendar view. Counting entries instead of dates answers a different question entirely.

Collection principle. Name both ends of a window; “recent” is not a boundary.

See one entry through four windows

Test “Rolling Windows Are Inclusive” by viewing one entry through Today, 7 days, 30 days, and calendar. State whether each view copies data or applies another predicate, and separate the questions answered by device-local date and absolute timestamp. Creating fake rows for blank days means the model has begun storing obligation.

Query it

Test 7-day and 30-day windows across a month boundary and a year boundary. Include month end, year end, near-midnight creation, multiple entries on one day, and status = 'live'. Explain the predicates and indexes that produce the answer, not only the final count.

Memory should lead back

Dates and keywords make return paths without judging the writing. When search reads the same original and transcribed state and tags retain prompt provenance, one collection truly owns its history.

Code

Compute inclusive calendar windows·python
from datetime import date, timedelta

def inclusive_window(end_iso: str, days: int):
    if days < 1:
        raise ValueError("days must be positive")
    end = date.fromisoformat(end_iso)
    start = end - timedelta(days=days - 1)
    return start.isoformat(), end.isoformat()

assert inclusive_window("2030-01-07", 7) == ("2030-01-01", "2030-01-07")
print(inclusive_window("2030-01-30", 30))

External links

Exercise

Test 7-day and 30-day windows across a month boundary and a year boundary.
Hint
Include boundary dates and blank days.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.