diff options
author | Michael J Gruber <git@drmicha.warpmail.net> | 2011-04-20 11:12:11 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-04-20 19:23:16 -0700 |
commit | f1e9c548ce45005521892af0299696204ece286b (patch) | |
tree | 6387f371b2dcb5c837325b661aa04322d5c5863f /Documentation/CodingGuidelines | |
parent | Git 1.7.3 (diff) | |
download | tgif-f1e9c548ce45005521892af0299696204ece286b.tar.xz |
date: avoid "X years, 12 months" in relative dates
When relative dates are more than about a year ago, we start
writing them as "Y years, M months". At the point where we
calculate Y and M, we have the time delta specified as a
number of days. We calculate these integers as:
Y = days / 365
M = (days % 365 + 15) / 30
This rounds days in the latter half of a month up to the
nearest month, so that day 16 is "1 month" (or day 381 is "1
year, 1 month").
We don't round the year at all, though, meaning we can end
up with "1 year, 12 months", which is silly; it should just
be "2 years".
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)
Tests and inspiration by Jeff King.
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'Documentation/CodingGuidelines')
0 files changed, 0 insertions, 0 deletions