Skip to content

Commit

Permalink
try again
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Rychlewski authored and Greg Rychlewski committed Aug 6, 2024
1 parent 1b1f1fa commit 0012b28
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/postgrex/extensions/interval.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,19 @@ defmodule Postgrex.Extensions.Interval do
def decode(type) do
quote location: :keep, generated: true do
<<16::int32(), microseconds::int64(), days::int32(), months::int32()>> ->
type_mod = var!(mod)
precision = if type_mod, do: type_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 @@ -79,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 @@ -90,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 @@ -122,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 0012b28

Please sign in to comment.