git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Michael J Gruber <git@drmicha.warpmail.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] date: avoid "X years, 12 months" in relative dates
Date: Wed, 20 Apr 2011 06:18:00 -0400	[thread overview]
Message-ID: <20110420101800.GA24035@sigill.intra.peff.net> (raw)
In-Reply-To: <1d0633318ffc778dfcc1c32ecf80fca0327349d6.1303290693.git.git@drmicha.warpmail.net>

On Wed, Apr 20, 2011 at 11:12:11AM +0200, Michael J Gruber wrote:

> 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

  reply	other threads:[~2011-04-20 10:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-20  5:24 [PATCH/RFH] date: avoid "X years, 12 months" in relative dates Jeff King
2011-04-20  9:12 ` [PATCH] " Michael J Gruber
2011-04-20 10:18   ` Jeff King [this message]
2011-04-20 11:00     ` Michael J Gruber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110420101800.GA24035@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@drmicha.warpmail.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).