Fix formula for converting Duration into google.protobuf.Duration#410
Fix formula for converting Duration into google.protobuf.Duration#410whatyouhide merged 1 commit intomainfrom
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.
I expected elixir to have a better API for that, but I didn't find one 🤔
There was a problem hiding this comment.
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.
From a couple weeks ago: elixir-lang/elixir@dd608c9
There was a problem hiding this comment.
TIL :)
I thought it was only info about how many digits of precision we could expect.
There was a problem hiding this comment.
TIL ... I needed that extra context around precision as well, I was YOLO it
There was a problem hiding this comment.
Ok, @whatyouhide, per our discussion, this is actually correct, right?
There was a problem hiding this comment.
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.
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.