git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] date: avoid "X years, 12 months" in relative dates

From
Jeff King <peff@peff.net>
Date
Apr 20, 2011, 10:18 UTC
Message-ID
<20110420101800.GA24035@sigill.intra.peff.net>
In-Reply-To
<1d0633318ffc778dfcc1c32ecf80fca0327349d6.1303290693.git.git@drmicha.warpmail.net>
On Wed, Apr 20, 2011 at 11:12:11AM +0200, Michael J Gruber wrote:
Show 13 quoted lines
> Implement this differently with months of size
> 
>   onemonth = 365/12
> 
> so that
> 
>   totalmonths = (long)( (days + onemonth/2)/onemonth )
>   years = totalmonths / 12
>   months = totalmonths % 12
> 
> In order to do this without floats, we write the first formula as
> 
>   totalmonths = (days*12*2 + 365) / (365*2)
Well now I feel like an idiot. Algebra to the rescue.

The extra multiplications introduce the possibility of overflow, but since the number of days was arrived at by dividing an unsigned long number of seconds by 86400, we are guaranteed to have room to multiply by 24. :)

So looks good to me.
-Peff
Previous: Michael J GruberNext: Michael J Gruber
Message 3 of 4 in “date: avoid "X years, 12 months" in relative dates”
  1. date: avoid "X years, 12 months" in relative datesJeff King, Apr 20, 2011
  2. date: avoid "X years, 12 months" in relative datesMichael J Gruber, Apr 20, 2011
  3. Jeff KingApr 20, 2011
  4. Michael J GruberApr 20, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.