The Zune Freeze — Java Bug Hunt

Inspired by December 31st, 2008 — the day every Microsoft Zune froze.

  • Language: Java
  • Layer: Backend
  • Difficulty: Medium
  • Concepts: Dates, Leap Years
  • Modelled on: Microsoft Zune · 2008
  • Visible tests: day one is January 1st, 1980; day 366 of a leap year stays in that year; day 367 starts the next year
  • Reward: 50 XP for a complete fix

Briefing

Inspired by December 31st, 2008 — the day every Microsoft Zune froze. The firmware's days-since-1980 conversion mishandled the 366th day of a leap year, and the players locked up until the calendar bailed them out.

ZuneClock.java converts a day count into (year, dayOfYear). Day 366 of a leap year currently rolls into the next year.

Bug report

BUG-Z2K8 · Priority: Critical · Reported by: everyone, on New Year's Eve

toDate(daysSince1980) — days start at 1 on Jan 1, 1980:

  • toDate(1) -> [1980, 1]
  • toDate(366) -> [1980, 366] (1980 is a leap year!)
  • toDate(367) -> [1981, 1]

Observed: day 366 returns [1981, 0].

Logs

[zune] boot day=10593 -> year=2009 dayOfYear=0 (expected 2008 / 366)

The code as shipped

ZuneClock.java (editable)

class ZuneClock {
    static boolean isLeap(int year) {
        return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
    }

    // days: 1-based count of days since Jan 1, 1980.
    static int[] toDate(int days) {
        int year = 1980;
        while (true) {
            int len = isLeap(year) ? 366 : 365;
            if (days > 365) {
                days -= len;
                year++;
            } else {
                break;
            }
        }
        return new int[] { year, days };
    }
}

Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More Java bug hunts.