johnkerl / miller

Miller is like awk, sed, cut, join, and sort for name-indexed data such as CSV, TSV, and tabular JSON
https://miller.readthedocs.io
Other
9.02k stars 217 forks source link

"mlr : time: invalid location name" error #1238

Open briantully opened 1 year ago

briantully commented 1 year ago

I just installed miller via homebrew on a Mac running Monterey (12.6.3). However when I try to run one of the example commands mlr --csv cat example.csv on a CSV file I created, I get the following error:

mlr : time: invalid location name I've tried tracking this down, and it seems to be related to an error within the golang time package when a valid timezone can't be established: https://github.com/golang/go/blob/master/src/time/zoneinfo.go#L642

Any idea how to resolve or work around this?

go version
go version go1.19.5 darwin/arm64
mlr --version
mlr 6.6.0 
johnkerl commented 1 year ago

@briantully sounds like a bug for when tz data is not available.

Either Miller should find a way to continue, or, at least fail more gracefully and informatively. (I don't yet know which ...)

johnkerl commented 1 year ago

@briantully I am curious -- what does echo $TZ print at your shell?

Also, for a workaround: export TZ="" at the shell, then re-run mlr --csv cat example.csv.

briantully commented 1 year ago

Hi @johnkerl ! thanks for the response. echo $TZ prints out the following:

echo $TZ
/usr/share/zoneinfo/US/Eastern

The workaround to set/export $TZ as an empty string seems to do the trick. Thanks for that!

So it seems there is some timezone/datetime issues with Go on macOS

johnkerl commented 1 year ago

@briantully Ah, thank you! So, TIL TZ can be a filename -- and moreover could be a filename in Miller 5 and below.

It's not just a MacOS issue, as on Linux as well I see

$ export TZ=/usr/share/zoneinfo/US/Eastern

$ mlr cat /dev/null
mlr :  time: invalid location name

$ mlr5 cat /dev/null
[no error message here]

I'm sure this can be accommodated in the Miller Go port, with a bit more effort on my part. Stay tuned! :)

chrisbitmead commented 1 year ago

I just installed miller via choco on Windows, and no matter what I do I get mlr: TZ environment variable appears malformed: "Asia/Taipei"

My TZ is in fact set (correctly) to Asia/Taipei.

johnkerl commented 1 year ago

Hi @chrisbitmead -- I can't reproduce this on my Windows machine (but note I do have Go installed on that machine

To debug a bit, can you please copy/paste the output of:

?

johnkerl commented 1 year ago

Also, this may be related ... https://github.com/golang/go/issues/21881

chrisbitmead commented 1 year ago

@johnkerl

$ mlr version
mlr: TZ environment variable appears malformed: "Asia/Taipei"

$ TZ=

$ mlr version
mlr version 6.8.0 for windows/amd64/go1.18.10

$ TZ=Asia/Istanbul

$ mlr version
mlr: TZ environment variable appears malformed: "Asia/Istanbul"

$ TZ=America/New_York
$ mlr version
mlr: TZ environment variable appears malformed: "America/New_York"

$$ TZ=GMT

$ mlr version
mlr: TZ environment variable appears malformed: "GMT"

$ TZ=UTC
$ mlr version
mlr version 6.8.0 for windows/amd64/go1.18.10

$ TZ=Local
$ mlr version
mlr version 6.8.0 for windows/amd64/go1.18.10
johnkerl commented 1 year ago

OK @chrisbitmead this does indeed sound like https://github.com/golang/go/issues/21881

So, here's a weird workaround: install Go (you don't need to use it -- just install it). Version 1.20.5 is fine.

(Background is that on Windows, for some very odd reason, the timezone-database files aren't included in built programs. But the Go tools have the timezone database included, so if you install the former -- and don't even use them -- you get the latter for free.)

chrisbitmead commented 1 year ago

@johnkerl a bit of a read through that (long and arduous) thread seems to indicate that one has the option to manually specify the inclusion of the timezone library when building it, which you should probably do on Windows.

[ I think golang ought to use Windows timezone APIs on windows, but that's not your problem ]

I'm probably not going to install golang, because at least for now, I have no need for timezone features in mlr, and will just set TZ=

AnabasisXu commented 2 weeks ago

I keep receiving:

❯ mlr --csv cat 3.csv
mlr: TZ environment variable appears malformed: "Asia/Shanghai"

I have set TZ="" for my Cygwin but it will mess up with the date function.