Fix the next reminder time in a medication app

Review the AI's codeHard40 min

Your task

Your medication reminder app lets someone pick a time of day for a dose. The phone keeps the time zone as a table of offset changes and works out, in UTC, when the next reminder fires.

An assistant wrote next_dose(after, dose, zone). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • Times are whole minutes counted from 1970-01-01 00:00. A UTC time u reads u + offset on the local clock, where offset is the one in force at u. Local midnights fall on multiples of 1,440.
  • zone: pairs [starts_at, offset], sorted by starts_at, which is a UTC time. From starts_at on, the offset is offset minutes, until the next pair starts. The first pair starts at 0.
  • dose: the dose's local time, in minutes after local midnight, from 0 to 1,439.
  • after: a UTC time.
  • Return the first UTC time strictly after after at which the dose fires.

Rules the tests check:

  • The dose fires once for every local date, at local time dose.
  • When the clock jumps forward over dose, that date's dose fires at dose read with the offset in force before the jump (on a night the clock jumps from 02:00 to 03:00, a 02:30 dose fires at 03:30).
  • When the clock goes back so that dose happens twice, that date's dose fires the first time only.
  • Offsets are from -1,080 to 1,080 minutes. Pairs are at least 2 days apart, and two pairs in a row can have the same offset.
  • after is from 10,000 to 100,000,000. The table has at most 1,000 pairs.

Then, in a sentence or two: how would you catch this kind of bug in review?

Examples

next_dose(after: int, dose: int, zone: list[list[int]]) -> int
Example 1
Inputnext_dose(29684880, 540, [[0, -300], [29549220, -240], [29891880, -300], [30083460, -240], [30426120, -300]])
Output29684940
Example 2
Inputnext_dose(29685060, 540, [[0, -300], [29549220, -240], [29891880, -300], [30083460, -240], [30426120, -300]])
Output29686380
Example 3
Inputnext_dose(29890920, 540, [[0, -300], [29549220, -240], [29891880, -300], [30083460, -240], [30426120, -300]])
Output29892360