{
  "id": 22688413,
  "title": "The date edge cases a period tracker has to get right",
  "url": "https://urgent.news/2026/11/29/the-date-edge-cases-a-period-tracker-has-to-get-right",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-29T23:57:37.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/alfredchaos/the-date-edge-cases-a-period-tracker-has-to-get-right-3l4n"
  },
  "original_language": null,
  "account": "Creating an accurate period tracker involves careful consideration of various edge cases that can affect the data. The core of this challenge lies in defining what constitutes a single day, and applying this definition consistently across all features. Storing period days as dates rather than timestamps simplifies the data model by eliminating time zones. However, this decision shifts complex cases to the edges, such as travel, daylight saving time changes, February 29th, and year boundaries. These edge cases are treated as non-negotiable in testing, as any regressions in these areas would indicate that the app's data is unreliable. One key aspect is ensuring that time zone changes do not shift a recorded day. A timestamp like 2026-11-03T00:30:00+08:00 remains Nov 2 in UTC. To verify this, a test records a date, switches the device time zone between America/Los_Angeles and Asia/Tokyo, and confirms that both the stored day and rendered day remain 2026-11-03. Daylight saving time (DST) changes are display issues, not storage concerns. During DST transitions, local time may be 23 or 25 hours long, making the distinction between calendar days complex. A test range spanning 2026-03-08 (US) and 2026-10-25 (EU) demonstrates that the number of days should match the number of calendar dates, not the number of 24-hour blocks. Leap years and year boundaries add another layer of complexity. February 29th exists in 2024 but not in 2025, requiring the app to handle arithmetic correctly in cycles spanning these dates. Tests parse, add or subtract days, and format records for 2024-02-29, 2025-02-28, 2025-12-31, and 2026-01-01. Adjacent periods merge into a single three-day period, while deleting a middle day splits it into two periods. This domain rule is distinct from UI state and must be tested by asserting cluster counts and lengths before and after deleting the middle day. The app must also account for unusual cycles, such as 63-day or 19-day cycles, which are user-specific facts rather than errors. Instead of clamping to the \"normal\" 28-day cycle, the app should keep the record, widen the prediction window, and lower the confidence label. Tests show that a history of [28, 29, 27, 63, 28] days should produce a much wider next-period range than [28, 29, 28, 27, 28]. The app should never assert a single date as the \"right\" answer, emphasizing that the data is user-specific. Finally, \"enough data\" is a boundary condition, not a subjective judgment. If predictions rely on at most the last six complete cycles, then the seventh and current cycles should not influence the result. A partially recorded current cycle is not considered valid evidence. Tests confirm that predictions with 6 or 7 complete cycles, asOfDate, yield identical output, and that calling with 0 or 1 cycles returns an explicit \"not enough data\" state instead of a fabricated date. Lastly, the app should treat time as an explicit input rather than relying on `new Date()` internally. By allowing the user to specify asOfDate, the app ensures consistent prediction results and enables tests to evaluate future dates without freezing the clock. Tests compare predictions at asOfDate = 2026-11-30 and 2026-12-15, verifying that cycle days differ but the underlying record interpretation remains the same. Finally, a test deletes all data, including raw records and derived views like predictions, statistics, and reminders. This ensures that cached predictions in the home screen are also removed, confirming that the app maintains the integrity of the stored date.",
  "summary": "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…",
  "summary_source": "publisher",
  "key_points": [
    "Edge cases include travel, DST changes, Feb 29th, and year boundaries",
    "Time zone changes must not shift recorded days, tested with device time zone switch",
    "App treats time as explicit input, not relying on new Date() internally"
  ],
  "editors_take": "Developers must handle complex time zone shifts and leap years correctly to prevent errors that would make the app's period tracking data unreliable for users.",
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}