[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: date: new options to parse input date with strptime(3)
From: |
Assaf Gordon |
Subject: |
Re: date: new options to parse input date with strptime(3) |
Date: |
Thu, 1 Aug 2019 03:24:29 -0600 |
User-agent: |
Mutt/1.11.4 (2019-03-13) |
Hello,
Thank you for the review.
(replying to both emails together)
On Wed, Jul 31, 2019 at 04:27:20PM +0100, Stephane Chazelas wrote:
> 2019-07-31 14:59:42 +0100, Pádraig Brady:
> > On 26/07/19 08:29, Assaf Gordon wrote:
> [...]
> > > The first patch adds '--date-format=FORMAT', where FORMAT is
> > > strptime(3) format.
> >
> > I like this, and think it's useful functionality.
> > It's equivalent to -f in date(1) on FreeBSD,
> > so we should probably support that short option
> [...]
>
> Note that busybox date has -D for that.
In gnu date(1), -f is already assigned to "--file" (batch processing).
I added the "-D" short option.
> [...] you can use the standard getdate() DATEMSK variable [...]
Based on past coreutils policies, I think new environment variables
won't be accepted to any program...
>> The second patch adds '--arith-format=FORMAT', where FORMAT is
>> limited
>> to years/months/days/hours/minutes/seconds (%Y/%m/%d/%H/%M/%S).
>
> The idea here is to support more generic numeric deltas.
> I'm not sure of the interface though. Perhaps --delta-format
> would be clearer.
I changed it to "--date-delta-format" (to match -D/--date-format).
Note that there's a difference between this and freebsd's -v:
The "--date-delta-format" takes the values from the same date string
(-d), so it also works with "--file" (batch processing).
> Or perhaps we should just support the
> FreeBSD -v option to apply the adjustments, which seems more direct
> and would further improve compat.
I like the FreeBSD -v method, and implemented it as well (in two
patches, to ease review).
The commit messages and tests provide many examples.
---
There could be many adjustment to these features, but I hope that if the
bulk of the code exists, adapting it will be easy.
One option, for example, is to do away with "--date-delta-format",
and accept the "-v" syntax in the "-d" string, so it will work
both from the command line and from a file:
date -D "%F" -d "2019-10-31" -v "+2y -100h"
printf "2019-10-31 +2y -100h" | date -D "%F" -f -
---
The attached patches are:
tests: add 'date -r/--reference=FILE' test
tests: add 'date -f/--file' (batch processing) test
date: add -D/--date-format=FORMAT option
date: add --date-delta-format=FORMAT option
date: add -v/--adjust-date=STRING option
date: expand -v=STR syntax to match FreeBSD
---
Comments and suggestions welcomed,
- assaf
date-strp-2019-08-01.patch.gz
Description: application/gunzip
- Re: date: new options to parse input date with strptime(3),
Assaf Gordon <=