The Alarm That Slept In — Python Bug Hunt
Inspired by the iPhone alarm bugs that made global news two New Years in a row — recurring alarms simply didn't fire when the date math wrapped wrong.
- Language: Python
- Layer: Backend
- Difficulty: Easy
- Concepts: Time, Modulo
- Modelled on: Apple iOS alarms
- Visible tests: an alarm later today is a simple difference; an alarm earlier than now wraps to tomorrow; an alarm for right now fires now
- Reward: 50 XP for a complete fix
Briefing
Inspired by the iPhone alarm bugs that made global news two New Years in a row — recurring alarms simply didn't fire when the date math wrapped wrong.
alarm.py: given the current time and a daily alarm time, return the minutes until it next fires. An alarm set for right now fires now (0 minutes).
Bug report
BUG-0700 · Priority: Everyone overslept · Reported by: the internet
minutes_until(now_h, now_m, alarm_h, alarm_m):
- alarm later today -> simple difference
- alarm earlier than now -> wraps to tomorrow
- alarm exactly now -> 0
Observed: alarms earlier in the day return NEGATIVE minutes, and the scheduler treats negatives as "never".
Logs
[alarm] now=23:30 alarm=07:00 -> -990 minutes -> skippedThe code as shipped
src/clock/alarm.py (editable)
# Minutes until the daily alarm next fires.
def minutes_until(now_h, now_m, alarm_h, alarm_m):
now = now_h * 60 + now_m
alarm = alarm_h * 60 + alarm_m
return alarm - now
Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More Python bug hunts.