git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>, Git Mailing List <git@vger.kernel.org>
Subject: Fix nasty approxidate bug
Date: Wed, 4 Jan 2006 19:33:55 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0601041930510.3169@g5.osdl.org> (raw)


Stupid me.

If approxidate ends up with a month that is ahead of the current month, it 
decrements the year to last year.

Which is correct, and means that "last december" does the right thing.

HOWEVER. It should only do so if the year is the same as the current year.

Without this fix, "5 days ago" ends up being in 2004, because it first 
decrements five days, getting us to December 2005 (correct), but then it 
also ends up decrementing the year once more to turn that December into 
"last year" (incorrect, since it already _was_ last year).

Duh. Pass me a donut.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
diff --git a/date.c b/date.c
index 3e11500..73037c7 100644
--- a/date.c
+++ b/date.c
@@ -640,7 +640,7 @@ unsigned long approxidate(const char *da
 	}
 	if (number > 0 && number < 32)
 		tm.tm_mday = number;
-	if (tm.tm_mon > now.tm_mon)
+	if (tm.tm_mon > now.tm_mon && tm.tm_year == now.tm_year)
 		tm.tm_year--;
 	return mktime(&tm);
 }

                 reply	other threads:[~2006-01-05  3:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=Pine.LNX.4.64.0601041930510.3169@g5.osdl.org \
    --to=torvalds@osdl.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /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).