]> git.ipfire.org Git - thirdparty/git.git/commit
approxidate: use deferred mday adjustments for "specials"
authorTuomas Ahola <taahol@utu.fi>
Thu, 21 May 2026 10:54:08 +0000 (13:54 +0300)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 May 2026 13:30:06 +0000 (22:30 +0900)
commitb809304101635d0fafc7644e82704ae653cacb07
treecfa0b6ce5da6bdeff93742735cb07b56e27799d2
parentbbe9b46ac826b5dad4f714513638dd223b6fe63f
approxidate: use deferred mday adjustments for "specials"

There are cases where the "wrap-to-yesterday" behavior of "tea" and
"noon" should be reverted later on down the line, so that "today tea"
and "tea today" won't yield different results.  However, the logic of
approxidate doesn't seem to lend itself particularly well to
such cases.

Start tackling the issue by reusing negative values of `tm->tm_mday`
field for deferred date adjustments which can be easily reverted, so
that the default logic of the special formats only applies if we don't
get any explicit date (mday) specification.  In particular, overwrite
the field with -1 in "today" and "yesterday", so that those formats will
be relative to the current date.  That makes specifications like "tea
yesterday" behave more sensibly: instead of going backwards to the
last tea-time and then a day back, Git will now understand that as the
tea-time of yesterday.

Replace the call of `update_tm()` in `date_time()` with the assignment
`tm->tm_mday = -2`.  Add the corresponding code to handle that in
`update_tm()`, wrapping to the previous day if the field still holds
such assignment, meaning that we haven't seen any better specification
for the day-of-month.  On the other hand, `mday=-3` would mean going
two days back and so on.  Even though such functionality isn't
actually needed by this patch, it won't add much complexity in the
code and is rather natural way to handle such values.

As `date_time()` won't no longer need the `now` struct, mark the
associated function parameters as unused.  The parameters themselves
have to stay, however, as those functions are called through pointers
in `approxidate_alpha`.  Add relevant tests to cover the changes.

Signed-off-by: Tuomas Ahola <taahol@utu.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
date.c
t/t0006-date.sh