bug-coreutils
[Top][All Lists]
Advanced

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

bug#33221: date command + 1 month


From: Nicolás Flores
Subject: bug#33221: date command + 1 month
Date: Thu, 1 Nov 2018 08:34:57 -0600

Thanks for the tip!

Saludos,
Nicolás Flores
@fosnss


El mié., 31 de oct. de 2018 a la(s) 20:27, Assaf Gordon (
address@hidden) escribió:

> tags 33221 notabug
> close 33221
> stop
>
> Hello,
>
> On 2018-10-31 5:08 p.m., Nicolás Flores wrote:
> > Date Bug detected: Wed Oct 31 17:02:41 CST 2018
> > when executing
> > # *date +%b*
> > Result:
> > *Oct *
> > This is Ok, but...
> >
> > # *date +%b -d '+1 month'*
> > Result: *Dec*
> > 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
> such cases:
>
> ==
>    $ 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:
>    year: 2018
>    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.
> Example:
>
>    $ date -d '2018-10-15 +1 month'
>    Thu Nov 15 00:00:00 MST 2018
>    $ date -d '2018-10-15 +1 month' +%b
>    Nov
>
> To do it in a script (obtaining the current year/month):
>
>    $ date -d "$(date +%Y-%m-15) +1 month" +%b
>    Nov
>
> To see more similar examples (e.g. with leap years, and February), read
> the following thread:
>     https://lists.gnu.org/archive/html/bug-coreutils/2018-02/msg00005.html
>
>
> As such, I'm closing this bug.
> Discussion can continue by replying to this thread.
>
> -assaf
>


reply via email to

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