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

runtime: fix time base for time.Now() #2007

Merged
merged 1 commit into from
Jul 20, 2021
Merged

runtime: fix time base for time.Now() #2007

merged 1 commit into from
Jul 20, 2021

Conversation

aykevl
Copy link
Member

@aykevl aykevl commented Jul 20, 2021

This function previously returned the atomic time, that isn't affected
by system time changes but also has a time base at some arbitrary time
in the past. This makes sense for baremetal platforms (which typically
don't know the wall time) but it gives surprising results on Linux and
macOS: time.Now() usually returns a time somewhere near the start of
1970.

This commit fixes this by obtaining both time values: the monotonic time
and the wall clock time. This is also how the Go runtime implements the
time.now function.


This fixes #68.

Note that with this change, runtime.AdjustTimeOffset is only available on baremetal systems. That doesn't seem like a problem to me.

This function previously returned the atomic time, that isn't affected
by system time changes but also has a time base at some arbitrary time
in the past. This makes sense for baremetal platforms (which typically
don't know the wall time) but it gives surprising results on Linux and
macOS: time.Now() usually returns a time somewhere near the start of
1970.

This commit fixes this by obtaining both time values: the monotonic time
and the wall clock time. This is also how the Go runtime implements the
time.now function.
@aykevl aykevl mentioned this pull request Jul 20, 2021
@deadprogram
Copy link
Member

⌚ thanks @aykevl now merging.

@deadprogram deadprogram merged commit 0348178 into dev Jul 20, 2021
@deadprogram deadprogram deleted the time-unix branch July 20, 2021 20:19
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