-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: time: add function to get time.Time for a given monotonic time #23227
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
Comments
I think we'd all consider this too disgusting to even consider, but you seem to have an actual use case, which is slightly horrifying, but makes this worth discussing. I marked this as a proposal for the proposal process, which is mostly on hold for the holidays until the new year. |
You can use |
There seem to be few cases in which this could be properly used (the OP's case would be one of the few). If you provide an historical monotonic value after a clock jump, or even after a smear, should Go return a value calculated based on the current relationship between the monotonic and real time clocks or the relationship that existed (or would have existed) at the time of the supplied value? And how would Go know anything but the current, sampled relationship? Anything exposed in the stdlib, especially a package as important as time itself, would and should be expected to have coherent, meaningful behavior around these use cases. |
Since this is a rare use case, and since I believe there is a way to do this without making any changes to the time package, I'm going to close this proposal. Please comment if you disagree. |
Assuming the monotonic time encoded in a I hope that this use case can be regarded as an experience report regarding time in Go:
|
I want to clarify that the suggested workaround does not depend on any assumptions about the type of monotonic time used in I think your further comments are concerned with more accurate use of To put it another way, |
What version of Go are you using (
go version
)?What did you expect to see?
A way to construct a time.Time from a value in the system's monotonic time.
(My use case is an integration with systemd: I am given a deadline to respond to a request, and the deadline is given only in terms of
CLOCK_MONOTONIC
. I want to convert that value to something I can use as a Context's Deadline.)What did you see instead?
There is no way I could find to accomplish this without resorting to reflect and unsafe.
Workaround (this should not be necessary):
The text was updated successfully, but these errors were encountered: