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

Make embedded timestamps timezone independent #64

Merged
merged 1 commit into from
Aug 12, 2021

Conversation

kpcyrd
Copy link
Contributor

@kpcyrd kpcyrd commented Aug 11, 2021

This is a follow-up for #61, the value of TZ still has an impact on the binary (removing the env::set_var call in one of the tests makes the test fail as well):

---- time::tests::test_timezone_utc stdout ----
thread 'time::tests::test_timezone_utc' panicked at 'assertion failed: `(left == right)`
  left: `"2021-08-04 14:34:03 +02:00"`,
 right: `"2021-08-04 12:34:03 +00:00"`', src/time.rs:46:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

With this patch SOURCE_DATE_EPOCH makes the embedded timestamp use UTC without build-time localization of the timezone. It also removes build-time localization when embedding the most-recent-git-commit timestamp (this didn't show up in our tests because we've tested with a sourcecode from a tarball).

The code could be simplified by always using UTC, then localize the timezone at runtime if needed.

I've dropped one of the tests because calling Local::now(); after now_data_time(); is always going to give you a greater value, unless SOURCE_DATE_EPOCH is explicitly set to a value in the future.

Thanks!

@baoyachi baoyachi self-requested a review August 12, 2021 15:07
@baoyachi baoyachi merged commit 9b1e291 into baoyachi:master Aug 12, 2021
@kpcyrd kpcyrd deleted the timezone-independent branch August 12, 2021 15:25
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.

None yet

2 participants