TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

History of Zero-Based Months?

52 pointsby expjpiover 2 years ago

7 comments

schotover 2 years ago
&quot;Why is day of the month 1-indexed but the month is 0-indexed in C?&quot;<p>This Twitter thread from November 2020[1] and its HackerNews discussion[2] seem relevant.<p>1: <a href="https:&#x2F;&#x2F;twitter.com&#x2F;hillelogram&#x2F;status&#x2F;1329228419628998665" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;hillelogram&#x2F;status&#x2F;1329228419628998665</a><p>2: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=25195287" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=25195287</a>
评论 #32617529 未加载
geriksonover 2 years ago
At least in Perl, the rationale for this (apart from copying C) is that it&#x27;s very easy to reference a list (array) of month names if the month indices are zero-based.
评论 #32617355 未加载
nayukiover 2 years ago
Zero-based months is awkward when printing as a number, but convenient when indexing an array:<p><pre><code> const MONTHS = [&quot;Jan&quot;, &quot;Feb&quot;, &quot;Mar&quot;, ..., &quot;Dec&quot;]; console.log(MONTHS[d.getMonth()]);</code></pre>
评论 #32620906 未加载
评论 #32621853 未加载
评论 #32622082 未加载
lofatdairyover 2 years ago
The same justification exists in JS (where it&#x27;s copied from Java which copies it from C). However, interestingly checking the FORTRAN IV specification documents for the PDP-10, it&#x27;s not implemented as a 3 letter ASCII abbreviation. That document dates to 1975, I don&#x27;t know if I can find if the date exists in the first version of the document, which should date to 1967. I was unable to find a reference to a builtin in the base FORTRAN II, which only provides 20 builtin functions, date not making the list. I think newer versions of FORTRAN77 has idate which is 1-indexed but I couldn&#x27;t find it in the older standard listed on wg5&#x27;s specification documents.<p>[^1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;PDP-10&#x2F;f40&#x2F;tree&#x2F;master&#x2F;doc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;PDP-10&#x2F;f40&#x2F;tree&#x2F;master&#x2F;doc</a>
photochemsynover 2 years ago
I think it all comes down to whether you&#x27;re counting elements as the primary goal. However, months are poorly defined relative to something like an astronomical year or a standard day, so they&#x27;re more like objects. That is to say, adding different months doesn&#x27;t give you the same number of days as a result.<p>Hence, dealing with months is perhaps a bit more like indexing variable-sized objects, and for that purpose traditionally, the array-of-pointers approach uses zero-based pointer arithmetic, which is what the designers might have been thinking.<p>Really however, the months should probably be treated more like structs, with the number of days in that month being a data member. This would allow sanity checks, i.e. entering Feb 30 should raise an error, but not May 30.
_OOps_over 2 years ago
I think it&#x27;s important to be able to work with mod(%) 12 for some operations on year &lt;--&gt; month relationship. All years have 12 months. For day of the month you need additional logic to handle diferent lengths... and other issues.
评论 #32624100 未加载
评论 #32618023 未加载
11235813213455over 2 years ago
&gt; One-based indexing for the year and day,<p>Year is 0 based too
评论 #32623070 未加载