approxidate: handle pending number for "specials"
commitc27cc94fad36ba46fea4a031d6df9d45b931f421
authorJeff King <peff@peff.net>
Fri, 2 Nov 2018 05:23:09 +0000 (2 01:23 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Nov 2018 11:49:53 +0000 (2 20:49 +0900)
tree3bebc46198a1579b1136470e081ff35f3ae95f2b
parentb4cfcde4db8f5787c6c8a3912b0f2667becd1995
approxidate: handle pending number for "specials"

The approxidate parser has a table of special keywords like
"yesterday", "noon", "pm", etc. Some of these, like "pm", do
the right thing if we've recently seen a number: "3pm" is
what you'd think.

However, most of them do not look at or modify the
pending-number flag at all, which means a number may "jump"
across a significant keyword and be used unexpectedly. For
example, when parsing:

  January 5th noon pm

we'd connect the "5" to "pm", and ignore it as a
day-of-month. This is obviously a bit silly, as "noon"
already implies "pm". And other mis-parsed things are
generally as silly ("January 5th noon, years ago" would
connect the 5 to "years", but probably nobody would type
that).

However, the fix is simple: when we see a keyword like
"noon", we should flush the pending number (as we would if
we hit another number, or the end of the string). In a few
of the specials that actually modify the day, we can simply
throw away the number (saying "Jan 5 yesterday" should not
respect the number at all).

Note that we have to either move or forward-declare the
static pending_number() to make it accessible to these
functions; this patch moves it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
date.c
t/t0006-date.sh