5 ms·
That does remind me: why that even is a thing? Ordering days of a week from zero can make sense since there is Monday/Sunday as a week start divide, and this ca
by mkotowski 5y ago
That does remind me: why that even is a thing? Ordering days of a week from zero can make sense since there is Monday/Sunday as a week start divide, and this can be seen as a bypass (0/7 as Sunday and 1 as a Monday), but with months?
- mikewhy 5y agohttps://stackoverflow.com/a/41992352 https://stackoverflow.com/a/41992352
- SippinLean 5y ago> it was copied from Java's JDK1.0 (1995) java.util.Date, which also had this quirk
- jauco 5y agoNo. It’s definitely older than that. https://mobile.twitter.com/hillelogram/status/1329228419628998665 https://mobile.twitter.com/hillelogram/status/13292284196289...
- Taywee 5y agoTwitter is such a bad platform for this. Code in images means it's completely inaccessible to the blind and very inaccessible to people with poor vision, and you can't copy and paste it into an editor for syntax highlighting or better examination.
- BrendanEich 5y agohttps://twitter.com/bahstgwamt/status/867609109276872704?s=20 https://twitter.com/bahstgwamt/status/867609109276872704?s=2...
- mikeryan 5y agoJust because the issue predated Java doesn’t preclude the fact that the initial JavaScript Date implementation was lifted from java.util.Date. Brandon Eich has explicitly stated it was so. https://maggiepint.com/2017/04/09/fixing-javascript-date-getting-started/ https://maggiepint.com/2017/04/09/fixing-javascript-date-get...
- tshaddox 5y agoZero indexing for arrays/collections generally makes sense. If you had the months in a normal array they would obviously be zero-indexed (unless you deliberately put a placeholder value in the first position in the array, which would be pretty weird since all the normal ways of getting the first thing in the array would break). The reason it apparently feels weird to many people to have months be zero indexed is that months are often referred to by their ordinal number, and ordinal numbers obviously start at 1.
- WA 5y agoEven if this is true, days in JS still start at 1. It is inconsistent.
- dmz73 5y agoZero indexing of arrays only makes sense in C because array variable is a pointer to first element of the array. In all languages that have actual array type with length and bounds checking, 1 would be a better way to index arrays most of the time and having specified valid range would be the best way.
- yunohn 5y ago> months are often referred to by their ordinal number What do you mean by “often”? Humans always use ordinal numbers for counting things like months, days, weeks, etc. There is no concept of 0 to be applied here, except for programming array indexing purposes.
- tshaddox 5y agoWhat I mean is that people use the ordinal number as the name of the month (as well as the day of the month). If you ask someone their birthday they’ll often say something like “five twenty, nineteen eighty-four.” This is a potential cause for confusion when writing computer code, because it’s very common for code to refer to items in a collection starting at zero.
- kevin_thibedeau 5y agoIt is lifted from C's struct tm. If you're maintaining tables of month names you're going to 0-index them so tm_mon is 0-based to facilitate that.
- lucian1900 5y agoThe week starts on Monday in most of the world. Date & time APIs must match local reality.
- pavel_lishin 5y agoWhen reality differs by locales, at least one "local reality" won't match the API.
- deleted 5y ago[deleted]