Habit (v0.2.0): local day, streak, reminder, medals #2

Merged
mnovak merged 1 commits from feature/habit into main 2026-11-17 11:58:28 +01:00
Owner

Day 2 (v0.2.0) of the core: liber-habit, plus two events in liber-library.

What

  • liber-habit (pure: time, UTC offset and rollover are parameters):
    • local_day(utc_ms, offset_min, rollover_hour) — the only day computation in Liber; 03:00 rollover by default. A session counts for the day it started.
    • Days read: sessions summed per day against the goal (N pages, or N active minutes).
    • The streak in calendar weeks (Monday–Sunday): at most one missed day per week; days before the first day read are not misses, and today is not a miss until it is over. A per-day calendar (read, forgiven, missed, today).
    • next_reminder (never today when the goal is met; none when off).
    • Medals: a pure function of the library with earned dates; "earlier" for undated imported reads; Day 3–5 medals listed but not earnable yet.
  • liber-library: Session.offset_min (optional, so old events still read), Op::HabitGoal (follows the person), Op::MedalSeen (only "seen" is stored). Export round trip includes both.

Tests (mandatory, all green; 74 test functions in the workspace)

  • day.rs 5: Prague DST both directions × rollover 0/3/5 (no skipped or doubled day, 23–25 h per day), a session across the rollover counts once, a property over 2,000 random moments.
  • streak.rs 6: one miss a week keeps it (also as a property over random weeks), a second miss ends it, days before the first day are not misses, the goal decides, and the total never decreases (property).
  • medals.rs 4: byte-identical recompute (also from events in reverse order); a Goodreads import earns first-book, books-10, re-read and let-go but no day medals; five moods; seen; the reminder rules.

Self-review

  • Time zones are not in the core: the device sends its offset with each session. That is right for "the day you read it", but a reader who flies east then west sees days counted where they were, which is intended.
  • The Prague DST model in the tests is hand-written (last Sunday of March/October at 01:00 UTC); it is checked against 2026's actual dates in a test.
  • Medal "earned" dates for undated imports are "earlier": honest, but they sort before every dated medal.
Day 2 (v0.2.0) of the core: `liber-habit`, plus two events in `liber-library`. ## What - **`liber-habit`** (pure: time, UTC offset and rollover are parameters): - `local_day(utc_ms, offset_min, rollover_hour)` — the only day computation in Liber; 03:00 rollover by default. A session counts for the day it started. - Days read: sessions summed per day against the goal (N pages, or N active minutes). - The streak in calendar weeks (Monday–Sunday): at most one missed day per week; days before the first day read are not misses, and today is not a miss until it is over. A per-day calendar (read, forgiven, missed, today). - `next_reminder` (never today when the goal is met; none when off). - Medals: a pure function of the library with earned dates; "earlier" for undated imported reads; Day 3–5 medals listed but not earnable yet. - **`liber-library`**: `Session.offset_min` (optional, so old events still read), `Op::HabitGoal` (follows the person), `Op::MedalSeen` (only "seen" is stored). Export round trip includes both. ## Tests (mandatory, all green; 74 test functions in the workspace) - day.rs 5: Prague DST both directions × rollover 0/3/5 (no skipped or doubled day, 23–25 h per day), a session across the rollover counts once, a property over 2,000 random moments. - streak.rs 6: one miss a week keeps it (also as a property over random weeks), a second miss ends it, days before the first day are not misses, the goal decides, and the total never decreases (property). - medals.rs 4: byte-identical recompute (also from events in reverse order); a Goodreads import earns first-book, books-10, re-read and let-go but no day medals; five moods; seen; the reminder rules. ## Self-review - Time zones are not in the core: the device sends its offset with each session. That is right for "the day you read it", but a reader who flies east then west sees days counted where they were, which is intended. - The Prague DST model in the tests is hand-written (last Sunday of March/October at 01:00 UTC); it is checked against 2026's actual dates in a test. - Medal "earned" dates for undated imports are "earlier": honest, but they sort before every dated medal.
mnovak added 1 commit 2026-11-17 11:58:27 +01:00
mnovak merged commit 4e68eec3c4 into main 2026-11-17 11:58:28 +01:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mnovak/Liber-public#2