After a while, something seemingly random started happening: any date in September or October displayed the wrong day name. I soon traced my problem back to a call to
For some reason it was causing the months index to become 0. After a bit of Googling I found an answer. The function
parseInt tries to be clever and guess which base you are using to convert your string to an integer. Although it usually defaults to base 10, when given strings starting with '0', it assumes that you are parsing an octal number (strings starting with '0x', it assumes hexadecimal).
A workaround is to always pass the radix to
For more information, check out Mozilla's Developer Center