GNU bug report logs - #38003
date --date=-1month gives same month today

Previous Next

Package: coreutils;

Reported by: Ilja Honkonen <ilja.honkonen <at> fmi.fi>

Date: Thu, 31 Oct 2019 14:35:03 UTC

Severity: normal

Tags: notabug

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Ilja Honkonen <ilja.honkonen <at> fmi.fi>, 38003 <at> debbugs.gnu.org
Subject: bug#38003: date --date=-1month gives same month today
Date: Thu, 31 Oct 2019 11:35:46 -0600
tag 38003 notabug
close 38003
stop

Hello,

On 2019-10-31 2:34 a.m., Ilja Honkonen wrote:
> Please CC me as I'm not on this list. Running date (GNU coreutils) 8.26 
> on fedora 30 today (date --utc  -I: 2019-10-31) with --date=-1month 
> gives the same month which doesn't make sense:
> $ date --utc -I --date=-1month
> 2019-10-01

date gained a "--debug" option that helps diagnosing the issue:

$ date --utc -I --debug --date=-1month
date: parsed relative part: -1 month(s)
[...]
date: using current date as starting value: '(Y-M-D) 2019-10-31'
[...]
date: warning: when adding relative months/years, it is recommended to 
specify the 15th of the months           <----
date: after date adjustment (+0 years, -1 months, +0 days),
date:     new date/time = '(Y-M-D) 2019-10-01 17:29:20'
date: warning: month/year adjustment resulted in shifted dates:
date:      adjusted Y M D: 2019 09 31    <----
date:    normalized Y M D: 2019 10 01    <----
[...]
date: final: (Y-M-D) 2019-10-01 17:29:20 (UTC)
2019-10-01

------

Subtracting 1 month from October 31st results in September 31st.
Since the date doesn't exist, it is normalized:
September 31st is "one day after September 30th", which
results in October 1st.

The "--debug" option also warns: when subtracting months,
it is recommended to specify the 15th (middle) of the month,
exactly to avoid such issues.

   $ date --utc -I --date="2019-10-15 -1month"
   2019-09-15

regards,
 - assaf





This bug report was last modified 5 years and 283 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.