Hacker News new | ask | show | jobs
by nayuki 1390 days ago
Zero-based months is awkward when printing as a number, but convenient when indexing an array:

    const MONTHS = ["Jan", "Feb", "Mar", ..., "Dec"];
    console.log(MONTHS[d.getMonth()]);
2 comments

Is subtracting 1 really that much an inconvenience, given how awkward they are?
Yes, that was always my theory for why months are 0-based. Back in the days of early Unix, this might have had a tiny performance benefit that was enough for them to choose that implementation.
I think that it should be unnecessary. The address of the array could be adjusted at compile-time so that one-based index numbers will be possible.
I think people are overestimating the features of compilers. Today's compilers might struggle with that. 70's compilers even more.