zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

interval.ex (864B)


      1 defmodule Postgrex.Extensions.Interval do
      2   @moduledoc false
      3   import Postgrex.BinaryUtils, warn: false
      4   use Postgrex.BinaryExtension, send: "interval_send"
      5 
      6   def encode(_) do
      7     quote location: :keep do
      8       %Postgrex.Interval{months: months, days: days, secs: secs, microsecs: microsecs} ->
      9         microsecs = secs * 1_000_000 + microsecs
     10         <<16::int32(), microsecs::int64(), days::int32(), months::int32()>>
     11 
     12       other ->
     13         raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, Postgrex.Interval)
     14     end
     15   end
     16 
     17   def decode(_) do
     18     quote location: :keep do
     19       <<16::int32(), microsecs::int64(), days::int32(), months::int32()>> ->
     20         secs = div(microsecs, 1_000_000)
     21         microsecs = rem(microsecs, 1_000_000)
     22         %Postgrex.Interval{months: months, days: days, secs: secs, microsecs: microsecs}
     23     end
     24   end
     25 end