I build a period tracker. The UI is a calendar, so people assume the hard part is drawing cells. It isn't. The hard part is agreeing on what "a day" is, then making every feature use that agreement.
We store period days as dates (2026-11-03), not timestamps. That single decision removes time zones from the data model. It also moves every difficult case to the edges, which is exactly where users live: traveling, daylight saving time, February 29, year boundaries.
These are the cases I treat as non-negotiable in tests. If any of them regress, the whole app is lying, because reminders, phase labels and predictions all read from the same day index.
1. Time zone changes must not move a recorded day
A timestamp like 2026-11-03T00:30:00+08:00 is still Nov 2 in UTC. If the app renders dates through UTC conversion, a record can shift by a day after a flight or a DST change.
Test: record Nov 3, set the device time zone to America/Los_Angeles, then to Asia/Tokyo, and assert the stored day and the rendered day are both 2026-11-03.
2. DST is a display problem, not a storage problem
On a DST transition day, local time may be 23 or 25 hours long. Two calendar days can be 23 hours apart. Any code that adds 24 * 60 * 60 * 1000 to an instant to get "tomorrow" is wrong twice a year.
Test: build a range across 2026-03-08 (US) and 2026-10-25 (EU), then assert the number of days matches the number of calendar dates, not the number of 24-hour blocks.
3. Leap day and year boundary
Feb 29 exists in 2024 and not in 2025. A cycle from 2024-02-01 to 2024-02-29 is 28 days. A cycle from 2025-12-31 to 2026-01-01 is 1 day. Both have to survive the same arithmetic path.
Test: parse, add days, subtract days, and format for 2024-02-29, 2025-02-28, 2025-12-31, 2026-01-01.
4. Adjacent marks merge, removing a middle day splits
The calendar lets people mark any date. If they mark Nov 3, 4 and 5, that is one period of three days, not three one-day periods. If they delete Nov 4, it becomes two periods. This is a domain rule, not a UI state.
Test: assert cluster count and lengths before and after deleting the middle day. Also assert that two clusters with a one-day gap stay separate, because the gap could be real.
5. Unusual cycles are kept, and confidence drops
A 63-day cycle or a 19-day cycle is a fact about the user, not an error. Clamping to "normal" 28-day values invents data. The right move is to keep the record, widen the predicted window, and lower the confidence label.
Test: a history of [28, 29, 27, 63, 28] should produce a much wider next-period range than [28, 29, 28, 27, 28]. Never assert a single date.
6. "Enough data" is a boundary, not a vibe
If predictions use at most the last six complete cycles, then the seventh cycle and the current, unfinished cycle must not change the result. A partially recorded current cycle is not evidence.
Test: call the prediction with 6 and with 7 complete cycles, same asOfDate, and assert identical output. Then call with 0 and 1 cycles and assert an explicit "not enough data" state instead of a fake date.
7. Time must be an input
Domain code should not call new Date() internally. Pass asOfDate explicitly so the same records always produce the same prediction, and so tests can describe a future date without freezing the clock.
Test: the same input at asOfDate = 2026-11-30 and 2026-12-15 yields different cycle days but the same underlying record interpretation.
8. Deletion is the last test, not the last feature
"Delete all data" has to remove the raw records and every derived view: predictions, statistics, reminders. A test that only checks the database is empty will miss the cached prediction the home screen renders from.
Test: create records, compute a prediction, delete all, then assert the prediction API returns the empty state and no reminder is scheduled.
Why bother
None of this makes a demo look better. It makes the quiet promises true: the date you tapped is the date stored, the estimate is an estimate, and the app says "not enough data" instead of guessing.
I work on Mori, a free Android period tracker that runs offline with no account. The public rules are on moricycle.com, and the glossary is the plain-language version if you want definitions rather than code.
