0

I'm having some weird issues with GNU coreutils date v8.4 (CentOS) that aren't occurring in v8.21 (Ubuntu/Mint).

On v8.4, I get the following output (I'm in PST):

$ date --version | head -n 1
date (GNU coreutils) 8.4
$ date -d '2014-11-08'
Sat Nov  8 00:00:00 PST 2014
$ date -d '2014-11-08T00:00:00'
Fri Nov  7 09:00:00 PST 2014

I'm assuming it's trying to timezone-correct for UTC, even though I didn't request it and this behavior doesn't occur on my local Linux Mint machine.

Okay, so I'll add a timezone specifier, as specified by W3. On my machine:

$ date --version | head -n 1
date (GNU coreutils) 8.21
$ date -d '2014-11-08T00:00:00-0800'
Sat Nov  8 00:00:00 PST 2014
$ date -d '2014-11-08T00:00:00-08:00'
Sat Nov  8 00:00:00 PST 2014

Great. But on CentOS:

$ date --version | head -n 1
date (GNU coreutils) 8.4
$ date -d '2014-11-08T00:00:00-0800'
date: invalid date `2014-11-08T00:00:00-0800'
$ date -d '2014-11-08T00:00:00-08:00'
date: invalid date `2014-11-08T00:00:00-08:00'

EDIT: Another one that doesn't work, using date's own output:

$ date -d "$(date -Ihours)"
date: invalid date `2014-11-08T13-0800'

The following does work:

$ date -d '2014-11-08 00:00:00 -08:00'
Sat Nov  8 00:00:00 PST 2014

but, due to completely unrelated requirements, I can't have any spaces in my date string.

I'm quite perplexed. I looked for recent changes to date but didn't see anything that looks promising.

My question: How can I get date to either not change my timezones at all (preferable), or accept timezone input from a human-readable string without spaces?

wchargin
  • 1,091
  • @Costas mmm, close, but I don't think so. I would rather have it be timezone-agnostic instead of picking a specific timezone. Just "use local time everywhere." – wchargin Nov 08 '14 at 22:15

1 Answers1

3

Check again the link you posted, there's a commit message:

date: support parsing of ISO-8601-with-"T" dates

It was implemented in coreutils 8.13 (see changelog).

don_crissti
  • 82,805
  • Oh! I had assumed that v8.13 meant v8.1.3. Thanks for the clarification. – wchargin Nov 08 '14 at 22:46