One of the best parts of doing software development is that you're always learning something new. Like, for example, I thought I'd seen every iteration on bad date handling code. But today, I learned something new.
Katharine picked up a pile of tickets, all related to errors with date handling. For months, the code had been running just fine, but in November there was an OS upgrade. "Ever since," the users complained, "it's consistently off by a whole month!" This was a bit of a puzzle, as there's nothing in an OS upgrade that should cause date strings to be consistently off by a whole month. Clearly, there must be a bug, but why did it only now start happening? Katharine pulled up the C code, and checked.
static const char *month_name[] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul"
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
};
It took a few passes before Katharine spotted the problem. Once she did, though, it was perfectly clear that the OS upgrade had nothing to do with it, and the userbase clearly had not been checking the output of the program since July.
If you haven't spotted it yet, note the missing ",
" after "Jul"
. In C, you're allowed to concatenate strings if a line ends with a string and the next line starts with a string, so this calendar goes from "Jun" straight to "JulAug", then the eight month of the year is "Sep".
Even after making the fix, several of the users were happy that "They fixed whatever the OS upgrade broke," but wished "they didn't change things that were working just fine!"