coreutils
[Top][All Lists]
Advanced

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

Re: Enhancement request to GNU date


From: Stephane Chazelas
Subject: Re: Enhancement request to GNU date
Date: Wed, 23 Oct 2019 17:13:46 +0100
User-agent: NeoMutt/20171215

2019-10-17 14:22:53 +0300, Yair Lenga:
[...]
> Would like to ask that you will consider the following extension to 'date'.
> The change will make it easier to perform basic date manipulations in
> scripts.
> 
> The request is to add the following 'suffixes' to the date (similar to the
> way relative dates are supported):
> * EOM - last date of the month
> * BOM - beginning of the month
> * EOY - last date on the year
> * BOY - first date of the year
> * prev EOM - last day previous month
> * next EOM - last day next month
> * prev EOY, next EOY - ditto.
> 
> While all of the constructs can be achieved today, they require multiple
> calls to date, with cumbersome formatting. Having those as "built-in" will
> make it easier to perform date manipulations.
> 
> Consider getting the number of days in the previous month
> Now:
> INPUT=2019-02-28
> date +'%d' -d "$(date +'%Y-%m-01' -d "$INPUT") -1day"
> Using PREV EOM
> date +'%d' -d "$INPUT prev EOM"
> 
> Thank you for taking time to look into this request. Any feedback is
[...]

For the record, with the ast-open implementation of date (like
the ksh93 date builtin if built as part of ast-open):

$ ast-date -d 'this month, yesterday' +%d
30
$ ast-date -d 'final day in last month' +%d
30
$ ast-date -d 'final day in december this year' +%F
2019-12-31
$ ast-date -d '1st day in january' +%F
2019-01-01

See more examples of what it supports at 
https://github.com/att/ast/blob/ksh93u/src/cmd/tests/date.dat

-- 
Stephane




reply via email to

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