Re: Improve on 'approxidate'
- From
Jeff King <peff@peff.net>
- Date
- Aug 30, 2009, 22:35 UTC
- Message-ID
- <20090830223558.GA29807@coredump.intra.peff.net>
- In-Reply-To
- <alpine.LFD.2.01.0908221438450.3158@localhost.localdomain>
On Sat, Aug 22, 2009 at 03:10:07PM -0700, Linus Torvalds wrote:
Show 11 quoted lines
> unsigned long approxidate(const char *date)
> {
> int number = 0;
> @@ -881,21 +911,24 @@ unsigned long approxidate(const char *date)
> time_sec = tv.tv_sec;
> localtime_r(&time_sec, &tm);
> now = tm;
> +
> + tm.tm_year = -1;
> + tm.tm_mon = -1;
> + tm.tm_mday = -1;This breaks relative dates like "3.months.ago", because approxidate_alpha needs to see the "current" date in tm (and now it sees -1, subtracts from it, and assumes we are just crossing a year boundary because of the negative). 3.years.ago is also broken, but I don't think 3.days.ago is.
Probably we just need to pass "now" to approxidate_alpha, and it needs to call update_tm under the case for "months" and "years" (and I haven't quite figured out why those are not part of the "tl" list). Unfortunately, I'm out of time to look at it more right now, but I'll take a look tonight or tomorrow if you don't beat me to it.
-Peff