-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,15 +163,22 @@ defmodule Google.Protobuf do | |
|
|
||
| iex> from_duration(Duration.new!(second: 1, microsecond: {500_000, 6})) | ||
| %Google.Protobuf.Duration{seconds: 1, nanos: 500_000_000} | ||
|
|
||
| iex> from_duration(Duration.new!(hour: 1, minute: 2, microsecond: {500_000, 6})) | ||
| %Google.Protobuf.Duration{seconds: 3720, nanos: 500_000_000} | ||
|
|
||
| iex> from_duration(Duration.new!(minute: 2, microsecond: {6_500_000, 6})) | ||
| %Google.Protobuf.Duration{seconds: 126, nanos: 500_000_000} | ||
| """ | ||
| @doc since: "0.15.0" | ||
| @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) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 🤔
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is the correct implementation.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From a couple weeks ago: elixir-lang/elixir@dd608c9
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, @whatyouhide, per our discussion, this is actually correct, right?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@v0idpwn you can use
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't mean the
v0idpwn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| struct(Google.Protobuf.Duration, %{ | ||
| seconds: duration.second, | ||
| nanos: microsecond * 1_000 | ||
| seconds: seconds, | ||
| nanos: rem(microsecond, 1_000_000) * 1_000 | ||
| }) | ||
| end | ||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.