tags 33221 notabug
Post by NicolÃ¡s Flores
Date Bug detected: Wed Oct 31 17:02:41 CST 2018
# *date +%b*
This is Ok, but...
# *date +%b -d '+1 month'*
Jump in the month of *November*
Indeed - that is the case, but it is not a bug.
It is a limitation of date's internal working .
date has a new --debug option that helps in troubleshooting
$ date --debug -d '+1 month'
date: parsed relative part: +1 month(s)
date: input timezone: system default
date: using current time as starting value: '20:17:28'
date: using current date as starting value: '(Y-M-D) 2018-10-31'
date: starting date/time: '(Y-M-D) 2018-10-31 20:17:28'
**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) 2018-12-01 19:17:28'
date: warning: daylight saving time changed after date adjustment
**date: warning: month/year adjustment resulted in shifted dates:**
**date: adjusted Y M D: 2018 11 31**
date: normalized Y M D: 2018 12 01
date: '(Y-M-D) 2018-12-01 19:17:28' = 1543717048 epoch-seconds
date: timezone: system default
date: final: 1543717048.174426822 (epoch-seconds)
date: final: (Y-M-D) 2018-12-02 02:17:28 (UTC)
date: final: (Y-M-D) 2018-12-01 19:17:28 (UTC-07)
Sat Dec 1 19:17:28 MST 2018
I highlighted three lines in the debug output.
When you added a month, internally date converted it to:
month: 10+1 = 11
day: 31 (today's date).
Then, date recognized that 31st of November is not a valid date,
and normalized it to Dec 1st.
The debug output includes a warning/recommendation:
when adding/subtracting months, it is recommended to start from the
15th of the month.
$ date -d '2018-10-15 +1 month'
Thu Nov 15 00:00:00 MST 2018
$ date -d '2018-10-15 +1 month' +%b
To do it in a script (obtaining the current year/month):
$ date -d "$(date +%Y-%m-15) +1 month" +%b
To see more similar examples (e.g. with leap years, and February), read
the following thread:
As such, I'm closing this bug.
Discussion can continue by replying to this thread.