Y
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
stingraycharles
1390 days ago
Is subtracting 1 really that much an inconvenience, given how awkward they are?
link
pvorb
1390 days ago
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.
link
zzo38computer
1389 days ago
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.
link
pvorb
1386 days ago
I think people are overestimating the features of compilers. Today's compilers might struggle with that. 70's compilers even more.
link