threads / discuss / 49840

approxidate woes

Subject: approxidate woes

## tl;dr

3 messages between Nov 15, 2018 and Nov 15, 2018.

replies: 2people: 2as markdown or json

Andreas Krey· Nov 15, 2018, 13:45 UTC · lore
Hi everybody,
I've now located why our backup repo shrinks every month:
  git gc --prune=2d
doesn't do what I expected, and differs a lot from --prune=48h.

The latter actually means 'older than two days', while the former is 'since the second day of this month, same time as now'.

Even '2d ago' does not help - '2 days ago' does.

Mildly irritating, and worse, hard to find in the documentation. I failed at the latter and fell back to the sources, finding './bin-wrappers/test-date approxidate' for trying.

Where would I look?
- Andreas
-- 
"Totally trivial. Famous last words."
From: Linus Torvalds <torvalds@*.org>
Date: Fri, 22 Jan 2010 07:29:21 -0800
Jeff King· Nov 15, 2018, 14:48 UTC · re: Andreas Krey · lore

Re: approxidate woes

On Thu, Nov 15, 2018 at 02:45:28PM +0100, Andreas Krey wrote:
Show 5 quoted lines
> I've now located why our backup repo shrinks every month:
> 
>   git gc --prune=2d
> 
> doesn't do what I expected, and differs a lot from --prune=48h.
Yeah, it understands "2 days", but not "d" as a unit.
I don't think "48h" does what you expect either:
  $ t/helper/test-date approxidate now
  now -> 2018-11-15 14:43:32 +0000
  $ t/helper/test-date approxidate 48h
  48h -> 2018-11-15 14:43:34 +0000
  $ t/helper/test-date approxidate 48.hours
  48.hours -> 2018-11-13 14:43:38 +0000

It might be reasonable to teach approxidate these obvious shorthands (one tricky one is "m"; normally I'd say "minute", but in Git timescales "month" is more likely).

Show 5 quoted lines
> Mildly irritating, and worse, hard to find in the documentation.
> I failed at the latter and fell back to the sources, finding
> './bin-wrappers/test-date approxidate' for trying.
> 
> Where would I look?

I don't think approxidate is really documented at all. It started as Linus's idea of "handle what people would probably say", and the fixes over the years have mostly been "eh, that's crazy, let's do better with this input".

You'd have to reverse engineer it a bit from the source, unfortunately.
-Peff
Jeff King· Nov 15, 2018, 14:54 UTC · re: Jeff King · lore

Re: approxidate woes

On Thu, Nov 15, 2018 at 09:48:54AM -0500, Jeff King wrote:
Show 10 quoted lines
> I don't think "48h" does what you expect either:
> 
>   $ t/helper/test-date approxidate now
>   now -> 2018-11-15 14:43:32 +0000
> 
>   $ t/helper/test-date approxidate 48h
>   48h -> 2018-11-15 14:43:34 +0000
> 
>   $ t/helper/test-date approxidate 48.hours
>   48.hours -> 2018-11-13 14:43:38 +0000
Whoops, those should all be:
  t/helper/test-tool date approxidate ...

in recent versions of Git (I was bisecting something earlier, and has a crufty test-date left over from an old version!).

Adding new unit aliases would be something like:
diff --git a/date.c b/date.c
index 9bc15df6f9..eb477d1601 100644
--- a/date.c
+++ b/date.c
@@ -1016,6 +1016,7 @@ static const struct typelen {
 	{ "minutes", 60 },
 	{ "hours", 60*60 },
 	{ "days", 24*60*60 },
+	{ "d", 24*60*60 },
 	{ "weeks", 7*24*60*60 },
 	{ NULL }
 };

but I suspect we need to tighten up the string matching a bit. I think
that would allow "2 dogs" to be parsed as "days".

-Peff

← back to recent threads