coreutils
[Top][All Lists]
Advanced

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

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


From: Assaf Gordon
Subject: date: new options to parse input date with strptime(3)
Date: Fri, 26 Jul 2019 01:29:23 -0600
User-agent: Mutt/1.11.4 (2019-03-13)

Hello,

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.
The second patch adds '--arith-format=FORMAT', where FORMAT is limited
to years/months/days/hours/minutes/seconds (%Y/%m/%d/%H/%M/%S).

Examples:

  # Specific date
  $ ./src/date --date-format '%d %b %Y' --date '17 Feb 1979' +%F
  1979-02-17

  # The 100th day of 2019
  $ ./src/date --date-format '%Y %j' --date '2019 100' +%F
  2019-04-10

  # Tuesday of the 10th week in 2018
  $ ./src/date --date-format '%Y %W %A' --date '2018 10 Tue' +%F
  2018-03-06

  # 2019-07-26 18:49:59, +49 hours, -10 minutes, -30 seconds:
  $ date --date-format '%Y%m%d %H%M%S' \
         --arith-format '%H %M %S' \
         --date '20190726 184959 49 -10 -30' \
        '+%F %T'
  2019-07-28 19:39:29

The test file (date-strp.pl) contains more usage examples.

This is just a proof of concept, and of course many things can be
improved and changed (assuming this feature is desired).

Comments and suggestions very welcomed,
 - assaf

Attachment: 0001-date-add-date-format-FORMAT-option.patch
Description: Text document

Attachment: 0002-date-add-arith-format-FORMAT-option.patch
Description: Text document


reply via email to

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