Why is day of the month 1-indexed but the month is 0-indexed in C?
twitter.com
twitter.com
For historical reasons.
When displaying the day of the month, we wanted to print "1" so we stored that.
For months, we wanted to print a 3 letter abbreviation, so we had a string ("JanFebMar...") and we stored an index-0 value to start at the first entry of the months string.
Months are a string array.
It seems intuitive to me. If you looked at a calendar and typed the data, that’s what you’d end up with.
And days can be string as well: "1st November".
If we go all the way back, one could say it was a mixed array of string and integer. September (7), October (8), November (9), and December (10) are linguistically ordinal names... but they’re all off by two since the deprecation of the Roman calendar.
(written 4 Freezy 229)
March (1) April (2) May (3) ... July (5) (named after Julius Caesar) August (6) (named after Augustus) September (7) ... etc.
The reason being in the ancient world all serious activity begins in the spring, especially war campaigns which were to be under the aegis of the god Mars, from which the name of the month.
Note that when we have a leap year we add the extra day to the end of the Roman year, that is at the end of February which is the last month of the year.
More precisely, we duplicate the sixth of the calends of March. This is why in French the leap year is called 'bisextile'.
Months often need to be translated to a name.
A day of month is not translated to a name.
In German I'd say that both two number dates (lit. "schedule a meeting for the ninth eighth") as well as month names (lit. "my birthday is on the eighteenth May") is common, so we might be more accustomed to thinking of months as numbers. If Roman emperors would've done a better job, we all would.
I think Windows does months as 1-indexed, but then makes a mess of days of the week.
We... do? America writes dates such as March 14th 2020 as 3/14/20. ISO 8601 is of course superior but I like the month-first approach, because "the 14th day of" doesn't tell you anything until you know "March", it seems more natural.
"Year" first would be more the point where it gets confusing, as when you really start reading the details from a calendar, the year would be first, too. (When you're actually talking, of course, the year is rarely mentioned.)
I'm just saying that going from how you say something in your native language to internal data representation is quite error-prone.
If we are having a casual conversation and I’m referring to a previous event that happened on the 14th, you can assume from context that I mean the 14th of the current or previous month (eg the 14th of November as of the writing of this comment). If it isn’t the current month (+-1 based on context), I can instead specify that I meant the 14th of September and you will understand that I mean the 14th of September this current year (again +-1 by context). If I meant the 14th of September, 1987, I will say the whole date. But since most date-based conversations have an implied context, being able to simply truncate dates for brevity is useful.
ISO 8601 is big-endian, European style is little-endian, and US-style is just kind of pointless.
US-style is middle-endian.
It is of course arbitrary, like anything in natural language; if I thought it were a matter of logic, I would have said something other than "feels more natural"!
I name-checked ISO 8601 for a reason; that's how I write my dates now, and as a developer, if you store dates as anything other than a Unix timestamp or ISO 8601, I judge you for it ;)
but you'll notice it puts the month before the day...
ISO-8601 does indeed put the month before the day, but it puts the year before the month too. The problem people have with the American format is that it's mixed. Y-m-d makes a lot of sense, but d-m-Y kind of does too. m/d/Y is just weird and it's literally the only country in the world to do it.
The problem is that the existence of both MM/DD/YY and DD/MM/YY makes dates less than the 13th of the month ambiguous. People do seem to get hung up on not going from smallest to largest unit (or the other way around), but the ambiguity is the real problem in my opinion. And of course it becomes a tribal thing, "the other guys are wrong about their format, we should keep ours and drop theirs". The best thing would be to just drop MM/DD/YY and DD/MM/YY in favor of _any_ format that is universally understood as unambiguous.
https://www.postgresql.org/docs/9.5/functions-datetime.html#...
[0] https://docs.oracle.com/javase/7/docs/api/java/util/Date.htm...
> I stopped at Unix 5, from 1974. It didn't even have a <time.h> file! In its <ctime.c> file, it stores the date as an array of integer values. The `tm` struct only starts appearing in Unix 7.
https://mobile.twitter.com/hillelogram/status/13292284386795...
https://minnie.tuhs.org/cgi-bin/utree.pl?file=V4/man/man3/ct...
It confirms that the day of the month element was one based. This function is different in earlier editions:
https://minnie.tuhs.org/cgi-bin/utree.pl?file=V3/man/man3/ct...
https://minnie.tuhs.org/cgi-bin/utree.pl?file=V1/man/man3/ct...