Skip to content

Commit

Permalink
Fix dialyzer issues with interval extension, part 2 (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski authored Aug 7, 2024
1 parent 6d16321 commit 66a4682
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/postgrex/extensions/interval.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,21 @@ defmodule Postgrex.Extensions.Interval do
end

def decode(type) do
quote location: :keep do
quote location: :keep, generated: true do
<<16::int32(), microseconds::int64(), days::int32(), months::int32()>> ->
precision = if var!(mod), do: var!(mod) &&& unquote(@precision_mask)

unquote(__MODULE__).decode_interval(
microseconds,
days,
months,
precision,
var!(mod),
unquote(type)
)
end
end

## Helpers

def decode_interval(microseconds, days, months, _precision, Postgrex.Interval) do
def decode_interval(microseconds, days, months, _type_mod, Postgrex.Interval) do
seconds = div(microseconds, 1_000_000)
microseconds = rem(microseconds, 1_000_000)

Expand All @@ -78,7 +76,7 @@ defmodule Postgrex.Extensions.Interval do
}
end

def decode_interval(microseconds, days, months, precision, Duration) do
def decode_interval(microseconds, days, months, type_mod, Duration) do
years = div(months, 12)
months = rem(months, 12)
weeks = div(days, 7)
Expand All @@ -89,6 +87,7 @@ defmodule Postgrex.Extensions.Interval do
seconds = rem(seconds, 60)
hours = div(minutes, 60)
minutes = rem(minutes, 60)
precision = if type_mod, do: type_mod &&& unquote(@precision_mask)

precision =
if precision in unquote(@unspecified_precision),
Expand Down Expand Up @@ -121,13 +120,13 @@ defmodule Postgrex.Extensions.Interval do
def decode(_) do
quote location: :keep do
<<16::int32(), microseconds::int64(), days::int32(), months::int32()>> ->
unquote(__MODULE__).decode_interval(microseconds, days, months, nil, Postgrex.Interval)
unquote(__MODULE__).decode_interval(microseconds, days, months, Postgrex.Interval)
end
end

## Helpers

def decode_interval(microseconds, days, months, _precision, Postgrex.Interval) do
def decode_interval(microseconds, days, months, Postgrex.Interval) do
seconds = div(microseconds, 1_000_000)
microseconds = rem(microseconds, 1_000_000)

Expand Down

0 comments on commit 66a4682

Please sign in to comment.