Volume XXII, number 280Wednesday, October 7, 2026Latest message 49 minutes ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

RFC patchapproxidate: make "today" wrap to midnight

5 messages between May 15, 2026 and May 16, 2026, from Tuomas Ahola, Junio C Hamano.

Plain Markdown or JSON for tools and agents. Diffs are folded; open one to read it.

Tuomas AholaMay 15, 2026, 20:58 UTC on lore

Although some commands do reject invalid approxidate expressions, in other cases those are simply evaluated as the current time. Oftentimes that is a perfectly good compromise to handle silly requests, but it isn't without rough edges.

Let's consider what "git log --since=today" should yield. As it happens that "today" isn't actually a valid approxidate format, the command currently tries to list commits with *future* timestamps. Perhaps it would make more sense if it returned the commits made since midnight---that is, during the current day.

Moreover, a revision parameter "@{today}" is currently outright rejected. Making "today" a valid approxidate time format could make a natural way to specify the state of the ref at the start of the current day.

Bind "today" to new function `date_today()` as an approxidate special. Make it return the last midnight if no specific time is given; i.e. retain the old behavior of "noon today" and such.

Signed-off-by: Tuomas Ahola <taahol@utu.fi>
---
Notes:
    The "Jan 5 today" test is adapted from
    
      c27cc94fad (approxidate: handle pending number for "specials", 2018-11-02):
    
    > (saying "Jan 5 yesterday" should not respect the number at all).
 date.c          | 10 ++++++++++
 t/t0006-date.sh |  2 ++
 2 files changed, 12 insertions(+)
Show changes to 2 files +12 −0

date.c, t/t0006-date.sh

diff --git a/date.c b/date.c
index 17a95077cf..343d6aab6f 100644
--- a/date.c
+++ b/date.c
@@ -1192,6 +1192,15 @@ static void date_never(struct tm *tm, struct tm *now UNUSED, int *num)
 	*num = 0;
 }
 
+static void date_today(struct tm *tm, struct tm *now, int *num UNUSED)
+{
+	if (tm->tm_hour == now->tm_hour &&
+	    tm->tm_min == now->tm_min &&
+	    tm->tm_sec == now->tm_sec)
+		date_time(tm, now, 0);
+	update_tm(tm, now, 0);
+}
+
 static const struct special {
 	const char *name;
 	void (*fn)(struct tm *, struct tm *, int *);
@@ -1204,6 +1213,7 @@ static const struct special {
 	{ "AM", date_am },
 	{ "never", date_never },
 	{ "now", date_now },
+	{ "today", date_today },
 	{ NULL }
 };
 
diff --git a/t/t0006-date.sh b/t/t0006-date.sh
index 53ced36df4..07bf6115ab 100755
--- a/t/t0006-date.sh
+++ b/t/t0006-date.sh
@@ -164,6 +164,7 @@ check_approxidate() {
 }
 
 check_approxidate now '2009-08-30 19:20:00'
+check_approxidate today '2009-08-30 00:00:00'
 check_approxidate '5 seconds ago' '2009-08-30 19:19:55'
 check_approxidate 5.seconds.ago '2009-08-30 19:19:55'
 check_approxidate 10.minutes.ago '2009-08-30 19:10:00'
@@ -187,6 +188,7 @@ check_approxidate 'last tuesday' '2009-08-25 19:20:00'
 check_approxidate 'July 5th' '2009-07-05 19:20:00'
 check_approxidate '06/05/2009' '2009-06-05 19:20:00'
 check_approxidate '06.05.2009' '2009-05-06 19:20:00'
+check_approxidate 'Jan 5 today' '2009-01-30 00:00:00'
 
 check_approxidate 'Jun 6, 5AM' '2009-06-06 05:00:00'
 check_approxidate '5AM Jun 6' '2009-06-06 05:00:00'

base-commit: 94f057755b7941b321fd11fec1b2e3ca5313a4e0
-- 
2.30.2
Junio C HamanoMay 16, 2026, 00:03 UTC in reply to Tuomas Ahola on lore

Re: [RFC PATCH] approxidate: make "today" wrap to midnight

Tuomas Ahola <taahol@utu.fi> writes:
Show 11 quoted lines
> Although some commands do reject invalid approxidate expressions,
> in other cases those are simply evaluated as the current time.
> Oftentimes that is a perfectly good compromise to handle silly
> requests, but it isn't without rough edges.
>
> Let's consider what "git log --since=today" should yield.
> As it happens that "today" isn't actually a valid approxidate
> format, the command currently tries to list commits with
> *future* timestamps.  Perhaps it would make more sense if
> it returned the commits made since midnight---that is,
> during the current day.
I actually am of two minds about this.  

What should "git log --until=today" do when you run it in the late afternoon? Wouldn't you want to see what you did in the morning and early afternoon?

Because we cannot define "today" as "--since=today means the latest midnight and later, while --until=today means until the end of today [*]" without introducing an extra hint to calls to approxidate() to tell it who is calling for what, it is impossible to give these two sensible behavior at the same time.

    Side note: but because the existing history is all about the past,
    "until the end of today" is by definition a synonym for "up to
    now", so defining "today" the same as "now" would make "until"
    behave just as sensibly as if we define it as "the end of today".

In practice, using "--until" to *not* truncate at all (which is what --until=now or --until=end.of.today would essentially mean) has no practical value, while "--since=beginning.of.today" does have more utility, allowing you to specify "the last 8 hours and 50 minutes" without knowing that it is now at 08:50 in the morning. So I am still in favor of interpreting "today" as "the latest midnight, the beginning of today" because that would give us a more useful behavior than other possible definitions. We may want to strengthen the justification behind the chosen definition of why we chose what we chose over any other time in today with something like what I said above, mentioning "--until".

Thanks.
Tuomas AholaMay 16, 2026, 11:36 UTC in reply to Tuomas Ahola on lore

[PATCH v2] approxidate: make "today" wrap to midnight

Although some commands do reject invalid approxidate expressions, in other cases those are simply evaluated as the current time. Oftentimes that is a perfectly good compromise to handle silly requests, but it isn't without rough edges.

Because of the silent acceptance, it is easy to forget that "today" isn't actually a valid approxidate format. That is a bit awkward because while the fallback logic of using the current time does make some sense, there is no deliberative decision behind such behavior of "today". Indeed, whatever (non-)action "today" currently has, is just an accidental side effect.

That means "git log --since=today" is currently unlikely to print anything at all as it tries to list commits dated with *future* timestamps. Arguably it would be more useful to list the commits of the current day---i.e. those made since midnight.

On the other hand, "git log --until=today" doesn't really filter commits at all. Changing the definition of "today" would make it return the commits made before the current day. That isn't without problems though---running "git log --until=today" in the late afternoon could reasonably include the work done earlier that day (as the command currently does do).

Still the utility of no-op "--until=today" is debatable and perhaps outweighed by the pros of having "--since=today" to mean "--since=midnight". The thing is that the approxidate machinery doesn't know about its consumers, so the meaning of "today" has to be the same for "--since" and "--until".

In fact, "git log --until=" is documented as
	`--until=<date>`::
	`--before=<date>`::
		Show commits older than _<date>_,

so excluding commits made today would actually match the documentation more closely.

Moreover, a revision parameter "@{today}" is currently outright rejected. Making "today" a valid approxidate time format could make a natural way to specify the state of the ref at the start of the current day.

Bind "today" to new function `date_today()` as an approxidate special. Make it return the last midnight if no specific time is given; i.e. retain the old behavior of "noon today" and such.

Document the new behavior of "git log --since=today" in rev-list-options.adoc.

Signed-off-by: Tuomas Ahola <taahol@utu.fi>
---
Intervall-diff mot v1:
1:  849f058baf ! 1:  86bcb70ac2 approxidate: make "today" wrap to midnight
    @@ Commit message
         Oftentimes that is a perfectly good compromise to handle silly
         requests, but it isn't without rough edges.
     
    -    Let's consider what "git log --since=today" should yield.
    -    As it happens that "today" isn't actually a valid approxidate
    -    format, the command currently tries to list commits with
    -    *future* timestamps.  Perhaps it would make more sense if
    -    it returned the commits made since midnight---that is,
    -    during the current day.
    +    Because of the silent acceptance, it is easy to forget that
    +    "today" isn't actually a valid approxidate format.  That is
    +    a bit awkward because while the fallback logic of using the
    +    current time does make some sense, there is no deliberative
    +    decision behind such behavior of "today".  Indeed, whatever
    +    (non-)action "today" currently has, is just an accidental
    +    side effect.
    +
    +    That means "git log --since=today" is currently unlikely to
    +    print anything at all as it tries to list commits dated with
    +    *future* timestamps.  Arguably it would be more useful to
    +    list the commits of the current day---i.e. those made since
    +    midnight.
    +
    +    On the other hand, "git log --until=today" doesn't really
    +    filter commits at all.  Changing the definition of "today"
    +    would make it return the commits made before the current day.
    +    That isn't without problems though---running "git log
    +    --until=today" in the late afternoon could reasonably include
    +    the work done earlier that day (as the command currently
    +    does do).
    +
    +    Still the utility of no-op "--until=today" is debatable and
    +    perhaps outweighed by the pros of having "--since=today" to
    +    mean "--since=midnight".  The thing is that the approxidate
    +    machinery doesn't know about its consumers, so the meaning
    +    of "today" has to be the same for "--since" and "--until".
    +
    +    In fact, "git log --until=" is documented as
    +
    +            `--until=<date>`::
    +            `--before=<date>`::
    +                    Show commits older than _<date>_,
    +
    +    so excluding commits made today would actually match the
    +    documentation more closely.
     
         Moreover, a revision parameter "@{today}" is currently outright
         rejected.  Making "today" a valid approxidate time format could
    @@ Commit message
         special.  Make it return the last midnight if no specific time
         is given; i.e. retain the old behavior of "noon today" and such.
     
    +    Document the new behavior of "git log --since=today" in
    +    rev-list-options.adoc.
    +
         Signed-off-by: Tuomas Ahola <taahol@utu.fi>
     
    + ## Documentation/rev-list-options.adoc ##
    +@@ Documentation/rev-list-options.adoc: ordering and formatting options, such as `--reverse`.
    + 
    + `--since=<date>`::
    + `--after=<date>`::
    +-	Show commits more recent than _<date>_.
    ++	Show commits more recent than _<date>_.  As a special case,
    ++	'today' means the last midnight.
    + 
    + `--since-as-filter=<date>`::
    + 	Show all commits more recent than _<date>_. This visits
    +
      ## date.c ##
     @@ date.c: static void date_never(struct tm *tm, struct tm *now UNUSED, int *num)
      	*num = 0;
 Documentation/rev-list-options.adoc |  3 ++-
 date.c                              | 10 ++++++++++
 t/t0006-date.sh                     |  2 ++
 3 files changed, 14 insertions(+), 1 deletion(-)
Show changes to 3 files +14 −1

Documentation/rev-list-options.adoc, date.c, t/t0006-date.sh

diff --git a/Documentation/rev-list-options.adoc b/Documentation/rev-list-options.adoc
index 2d195a1474..a5abadf689 100644
--- a/Documentation/rev-list-options.adoc
+++ b/Documentation/rev-list-options.adoc
@@ -23,7 +23,8 @@ ordering and formatting options, such as `--reverse`.
 
 `--since=<date>`::
 `--after=<date>`::
-	Show commits more recent than _<date>_.
+	Show commits more recent than _<date>_.  As a special case,
+	'today' means the last midnight.
 
 `--since-as-filter=<date>`::
 	Show all commits more recent than _<date>_. This visits
diff --git a/date.c b/date.c
index 17a95077cf..343d6aab6f 100644
--- a/date.c
+++ b/date.c
@@ -1192,6 +1192,15 @@ static void date_never(struct tm *tm, struct tm *now UNUSED, int *num)
 	*num = 0;
 }
 
+static void date_today(struct tm *tm, struct tm *now, int *num UNUSED)
+{
+	if (tm->tm_hour == now->tm_hour &&
+	    tm->tm_min == now->tm_min &&
+	    tm->tm_sec == now->tm_sec)
+		date_time(tm, now, 0);
+	update_tm(tm, now, 0);
+}
+
 static const struct special {
 	const char *name;
 	void (*fn)(struct tm *, struct tm *, int *);
@@ -1204,6 +1213,7 @@ static const struct special {
 	{ "AM", date_am },
 	{ "never", date_never },
 	{ "now", date_now },
+	{ "today", date_today },
 	{ NULL }
 };
 
diff --git a/t/t0006-date.sh b/t/t0006-date.sh
index 53ced36df4..07bf6115ab 100755
--- a/t/t0006-date.sh
+++ b/t/t0006-date.sh
@@ -164,6 +164,7 @@ check_approxidate() {
 }
 
 check_approxidate now '2009-08-30 19:20:00'
+check_approxidate today '2009-08-30 00:00:00'
 check_approxidate '5 seconds ago' '2009-08-30 19:19:55'
 check_approxidate 5.seconds.ago '2009-08-30 19:19:55'
 check_approxidate 10.minutes.ago '2009-08-30 19:10:00'
@@ -187,6 +188,7 @@ check_approxidate 'last tuesday' '2009-08-25 19:20:00'
 check_approxidate 'July 5th' '2009-07-05 19:20:00'
 check_approxidate '06/05/2009' '2009-06-05 19:20:00'
 check_approxidate '06.05.2009' '2009-05-06 19:20:00'
+check_approxidate 'Jan 5 today' '2009-01-30 00:00:00'
 
 check_approxidate 'Jun 6, 5AM' '2009-06-06 05:00:00'
 check_approxidate '5AM Jun 6' '2009-06-06 05:00:00'

base-commit: 94f057755b7941b321fd11fec1b2e3ca5313a4e0
-- 
2.30.2
Junio C HamanoMay 16, 2026, 13:35 UTC in reply to Tuomas Ahola on lore

Re: [PATCH v2] approxidate: make "today" wrap to midnight

Tuomas Ahola <taahol@utu.fi> writes:
Show 14 quoted lines
> Although some commands do reject invalid approxidate expressions,
> in other cases those are simply evaluated as the current time.
> Oftentimes that is a perfectly good compromise to handle silly
> requests, but it isn't without rough edges.
> ...
> Bind "today" to new function `date_today()` as an approxidate
> special.  Make it return the last midnight if no specific time
> is given; i.e. retain the old behavior of "noon today" and such.
>
> Document the new behavior of "git log --since=today" in
> rev-list-options.adoc.
>
> Signed-off-by: Tuomas Ahola <taahol@utu.fi>
> ---
I like this construction of argument.

How does this patch mesh with your earlier effort to make "noon" and "tea" more sensible? Should we eject the "today is now" step from that series and instead queue this patch in its place?

Thanks.
Tuomas AholaMay 16, 2026, 13:54 UTC in reply to Junio C Hamano on lore

Re: [PATCH v2] approxidate: make "today" wrap to midnight

Junio C Hamano <gitster@pobox.com> wrote:
Show 24 quoted lines
> Tuomas Ahola <taahol@utu.fi> writes:
> 
> > Although some commands do reject invalid approxidate expressions,
> > in other cases those are simply evaluated as the current time.
> > Oftentimes that is a perfectly good compromise to handle silly
> > requests, but it isn't without rough edges.
> > ...
> > Bind "today" to new function `date_today()` as an approxidate
> > special.  Make it return the last midnight if no specific time
> > is given; i.e. retain the old behavior of "noon today" and such.
> >
> > Document the new behavior of "git log --since=today" in
> > rev-list-options.adoc.
> >
> > Signed-off-by: Tuomas Ahola <taahol@utu.fi>
> > ---
> 
> I like this construction of argument.
> 
> How does this patch mesh with your earlier effort to make "noon" and
> "tea" more sensible?  Should we eject the "today is now" step from
> that series and instead queue this patch in its place?
> 
> Thanks.

Yes. I have already rebased the series on top of this patch. I will soon(ish) post v4 without "today is now" step.

--Tuomas

Back to recent threads