-
Notifications
You must be signed in to change notification settings - Fork 153
Fix formula for converting Duration into google.protobuf.Duration #410
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
Conversation
| @spec from_duration(Duration.t()) :: Google.Protobuf.Duration.t() | ||
| def from_duration(%Duration{} = duration) do | ||
| {microsecond, _precision} = duration.microsecond | ||
| seconds = div(to_timeout(duration), 1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expected elixir to have a better API for that, but I didn't find one 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the correct implementation. duration.microsecond is of type Calendar.microsecond/0, and the second element of the tuple should be used in the calculation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a couple weeks ago: elixir-lang/elixir@dd608c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL :)
I thought it was only info about how many digits of precision we could expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL ... I needed that extra context around precision as well, I was YOLO it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, @whatyouhide, per our discussion, this is actually correct, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expected elixir to have a better API for that, but I didn't find one 🤔
@v0idpwn you can use System.convert_time_unit/3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't mean the div/2 but the to_timeout. I would like to have Duration.to_unit(duration, :second)
|
@v0idpwn @whatyouhide do you think you could cut a release with the feature? |
Can't use
duration.secondbecause you may have minutes, weeks, etc to consider.