coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: date: new options to parse input date with strptime(3)


From: Stephane Chazelas
Subject: Re: date: new options to parse input date with strptime(3)
Date: Wed, 31 Jul 2019 16:27:20 +0100
User-agent: NeoMutt/20171215

2019-07-31 14:59:42 +0100, Pádraig Brady:
> On 26/07/19 08:29, Assaf Gordon wrote:
[...]
> > Some time ago there was a discussion relating to diffuculties of using
> > GNU date's parsing. There was a mention of how using strptime(3) makes
> > parsing explicit and easy.
> > 
> > I like that idea, and decided to try my hand at adding such options.
> > 
> > Attached is a proof of concept.
> > 
> > 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.

$ busybox date -d 120003 -D %H%M%S '+%F %T'
2019-07-31 12:00:03

For ast-open's date (also applies to ksh93's printf %T and all
ast utilities that parse dates), you can use the standard
(XPG / POSIX+XSI) getdate() DATEMSK variable which points to a
file that contains the rules to parse dates.

$ DATEMSK=/dev/fd/3 3<<<%H%M%S date -d 120003 '+%F %T'
2019-08-01 12:00:03
$ ksh93 -c 'DATEMSK=/dev/fd/3 3<<<%H%M%S printf "%(%F %T)T\n" 120003'
2019-08-01 12:00:03

-- 
Stephane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]