[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#36383: date command processes timezone differently when doing math
From: |
Assaf Gordon |
Subject: |
bug#36383: date command processes timezone differently when doing math |
Date: |
Wed, 26 Jun 2019 08:37:29 -0600 |
User-agent: |
Mutt/1.11.4 (2019-03-13) |
tag 36383 notabug
close 36383
stop
Hello,
On Tue, Jun 25, 2019 at 04:10:07PM -0700, Brian Woods wrote:
> When doing a math operation to a date command it appear to process the
> timezone differently.
[...]
>
> #echo $datNow
> 2019-06-25 15:21:34
>
> #date -d "$datNow + 1 minute" "+%Y-%m-%d %H:%M:%S" --debug
> date: parsed date part: (Y-M-D) 2019-06-25
> date: parsed time part: 15:21:34 UTC+01
> date: parsed relative part: +1 minutes
> date: input timezone: parsed date/time string (+01)
Thank you for providing detailed examples with "--debug",
makes things much easier to troubleshoot.
The issue is that a time string (HH:MM:SS) followed by a plus
sign and a number is *always* taken to be a time zone.
Using a value other than 1 will show it more clearly:
$ date -d "$datNow + 8 minutes" "+%Y-%m-%d %H:%M:%S" --debug
date: parsed date part: (Y-M-D) 2019-06-25
date: parsed time part: 15:21:34 UTC+08
date: parsed relative part: +1 minutes
date: input timezone: parsed date/time string (+08)
The "+8" part is treated as timezone,
and the remaining text ("minutes") is taken as a one-minute time
adjustment.
One solution is to just remove the plus sign:
$ date -d "$datNow 8 minutes" "+%Y-%m-%d %H:%M:%S" --debug
date: parsed date part: (Y-M-D) 2019-06-25
date: parsed time part: 15:21:34
date: parsed relative part: +8 minutes
date: input timezone: system default
[...]
2019-06-25 15:29:34
Another is to specify the time zone:
$ date -d "$datNow +00:00 +8 minutes" "+%Y-%m-%d %H:%M:%S" --debug
date: parsed date part: (Y-M-D) 2019-06-25
date: parsed time part: 15:21:34 UTC+00
date: parsed relative part: +8 minutes
date: input timezone: parsed date/time string (+00)
[...]
2019-06-25 09:29:34
More examples of adjusting time strings are here (your example is similar
to case #1):
https://lists.gnu.org/archive/html/bug-coreutils/2018-10/msg00126.html
As such, I'm closing this ticket but discussion can continue by replying
to this thread.
regards,
- assaf