GNU bug report logs -
#36383
date command processes timezone differently when doing math
Previous Next
Reported by: Brian Woods <bpwoods <at> gmail.com>
Date: Tue, 25 Jun 2019 23:23:02 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
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
This bug report was last modified 5 years and 326 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.