Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local time when TZ is not set #1649

Merged
merged 1 commit into from
Sep 17, 2024
Merged

Fix local time when TZ is not set #1649

merged 1 commit into from
Sep 17, 2024

Conversation

balki
Copy link
Contributor

@balki balki commented Sep 17, 2024

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

Do not override time.Local when TZ is empty or unset. It is already set correctly by go standard library.
@johnkerl
Copy link
Owner

Thank you @balki !! :)

@johnkerl johnkerl merged commit d1767e7 into johnkerl:main Sep 17, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants