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

Fix local time when TZ is not set #1649

Closed balki closed 2 months ago

balki commented 2 months ago

sec2localtime is returning UTC time unless TZ was explicitly set either via environment variable TZ or --tz cli fag. Golang sets time.Local correctly even without TZ. But it is overridden at SetTZFromEnv. When TZ is unset (i.e. ""), LoadLocation returns UTC doc.

If the name is "" or "UTC", LoadLocation returns UTC. If the name is "Local", LoadLocation returns Local.


❯ date
Tue 17 Sep 2024 10:41:02 AM EDT

❯ printf '{"ts": %s }' $(date +"%s") | go run cmd/mlr/main.go --jsonl put '$ts = sec2localtime($ts)'
{"ts": "2024-09-17 10:41:06"}

❯ printf '{"ts": %s }' $(date +"%s") | mlr --jsonl put '$ts = sec2localtime($ts)'
{"ts": "2024-09-17 14:41:09"}

❯ mlr --version
mlr 6.12.0

❯ env | grep TZ

❯ env | grep TZ || echo "not found"
not found
johnkerl commented 2 months ago

Thank you @balki !! :)