Subject: Re: bug#47476: relative date of -1 month shows the wrong month

From: Chris Elvidge <[email-masked]>
Date: Tue, 30 Mar 2021 10:39:57 +0100

On 29/03/2021 05:25 pm, Pádraig Brady wrote:
> On 29/03/2021 16:39, Lars Noodén wrote:
>> Severity: normal
>> Package: coreutils
>> Version: 8.32-4
>>
>> On March 29, 2021, if a relative date of '-1 month' is passed to 'date',
>> then the output shows March instead of February.
>>
>> $ date; date -d '-1 month'; date -d '1 month ago'; date -d 'last month';
>> Mon 29 Mar 2021 06:35:43 PM EEST
>> Mon 01 Mar 2021 05:35:43 PM EET
>> Mon 01 Mar 2021 05:35:43 PM EET
>> Mon 01 Mar 2021 05:35:43 PM EET
>>
>> The output shows March when it clearly should show February instead.
>> This impairs the usefulness of the program a lot on certain days.
> 
> This is a commonly reported issue.
> I agree the current operation is confusing.
> I'm working on a change to make the adjustment relative to the input 
> resolution.
> I.e. operate on a month basis in this case rather than days etc.
> The current FAQ (linked below) suggests the workaround of:
> 
>    date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B.'
> 
> cheers,
> Pádraig
> 
> https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#The-date-command-is-not-working-right_002e 
> 
> 

It's noticeable that (on my system, CYGWIN-NT and/or Raspbian) 'date 
-d"now -1month"' gives a definitely wrong answer, but 'dateadd now -1mo' 
gives a somewhat more reasonable answer. dateadd is from the dateutils 
package, sometimes dadd and/or dateutils.dadd.

$ date +"%Y-%m-%d %H:%M:%S"
2021-03-30 10:37:00

$ date -d"now -1 month" +"%Y-%m-%d %H:%M:%S"
2021-03-02 09:37:17

$ dateadd now -1mo -f"%Y-%m-%d %H:%M:%S"
2021-02-28 09:37:27

-- 

Chris Elvidge