<div dir="ltr"><div dir="ltr">On Sat, Sep 24, 2022 at 1:17 AM Ted Phelps via tz <<a href="mailto:tz@iana.org">tz@iana.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2022-09-24, Tony Finch wrote:<br>
> You might also like <a href="https://dotat.at/@/2008-09-10-counting-the-days.html" rel="noreferrer" target="_blank">https://dotat.at/@/2008-09-10-counting-the-days.html</a><br>
> (That does things the hard way, rather than relying on tm_yday)<br>
> and <a href="https://dotat.at/@/2008-09-15-the-date-of-the-count.html" rel="noreferrer" target="_blank">https://dotat.at/@/2008-09-15-the-date-of-the-count.html</a><br>
<br>
Wow, that's some clever math you've done there; far nicer than the <br>
clumsy approach I'd used to canonicalize the year, month and day.  It's <br>
a little slower than my clumsy approach in the case where the year, <br>
month and day are already in canonical form, but can be much faster when <br>
they're not.  I'll incorporate those changes into my git project in the <br>
coming days, thank you!<br></blockquote><div><br></div></div><span style="font-family:monospace;font-size:x-small">static inline int64_t daynum(int64_t year, int mon, int day)</span><br><span style="font-family:monospace;font-size:x-small">{</span><br><span style="font-family:monospace;font-size:x-small">    // Rotate the start of the year to March so that the troublesome</span><br><span style="font-family:monospace;font-size:x-small">    // leap day is last.  Also, make March month number 4 to simplify</span><br><span style="font-family:monospace;font-size:x-small">    // the calculation below.</span><br><span style="font-family:monospace;font-size:x-small">    if (mon > 2) {</span><br><span style="font-family:monospace;font-size:x-small">        mon += 1;</span><br><span style="font-family:monospace;font-size:x-small">    } else {</span><br><span style="font-family:monospace;font-size:x-small">        mon += 13;</span><br><span style="font-family:monospace;font-size:x-small">        year -= 1;</span><br><div class="gmail_quote"><font face="monospace" size="1">    }</font></div><div class="gmail_quote"><font face="monospace" size="1"><br>    // Compute the day number since the start of year 1.  This clever<br>    // expression is thanks to Tony Finch; see his blog post for a<br>    // detailed explanation of what's going on here:<br>    //     <a href="https://dotat.at/@/2008-09-10-counting-the-days.html">https://dotat.at/@/2008-09-10-counting-the-days.html</a><br>    return year * 1461 / 4 - year / 100 + year / 400 + mon * 153 / 5 + day - 428;<br>}</font><br><div><br></div><div>Assuming we want to model the proleptic Gregorian calendar, it would be nice if the output was linear over all inputs.  At the moment, for example, <font face="monospace">daynum(0, 2, 29)</font> and <font face="monospace">daynum(0, 3, 1)</font> both return <font face="monospace">-305</font>.</div></div></div>