Web lists-archives.com

Re: [Was: Re: policy around 'wontfix' bug tag




On 2018-02-06 12:32:06 +1100, Erik Christiansen wrote:
> On 05.02.18 09:39, Greg Wooledge wrote:
> > (*) One specific shell script use case was "Get the last date of a given
> > month."  Now, obviously you can just set up an array of hard-coded month
> > ending dates, and then write a function to determine whether the current
> > year is a leap year for the February case.  But if you want to do it with
> > GNU date -d, then you have to guess a magic incantation that actually
> > works.  Usually by trial and error.
> > 
> > Anyway, here's what I came up with:
> > 
> > lastday() {
> >     date +%Y-%m-%d -d "$1 1 day ago + 1 month"
> > }
> ...
> 
> > How does it work?  Who knows!
> 
> That's quite straightforward, I submit. Omitting the "+ 1 month", your
> expression is equivalent to: (with $1 substituted for example 1)
> 
> $ date +%Y-%m-%d -d "2016-03-01 - 1 day"
> 2016-02-29
> 
> which simply steps backward from first of the month to last of the
> previous. Then stepping forward a month merely avoids the need to input
> first of next month for last of this one.

Your explanation is incorrect (see my other mail on this subject).

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)