Packages

Interval/range operations on Decimal, DateTime, Integer, Float, etc. Ecto support for Postgres range types like int4range, daterange, tstzrange, etc. Implement intervals over your own custom data.

Retired package: Release invalid - Package did not compile correctly without Ecto and Postgrex

Current section

Files

Jump to
interval lib interval date.ex
Raw

lib/interval/date.ex

if Application.get_env(:interval, Interval.Date, true) do
defmodule Interval.Date do
@moduledoc false
use Interval, type: Date, discrete: true
if Code.ensure_loaded?(Interval.Support.Ecto) do
use Interval.Support.Ecto, ecto_type: :daterange
end
@spec size(t()) :: integer() | nil
def size(%__MODULE__{right: :unbounded}), do: nil
def size(%__MODULE__{left: :unbounded}), do: nil
def size(%__MODULE__{left: :empty, right: :empty}), do: 0
def size(%__MODULE__{left: {_, a}, right: {_, b}}), do: Date.diff(b, a)
@spec point_valid?(Date.t()) :: boolean()
def point_valid?(a), do: is_struct(a, Date)
@spec point_compare(Date.t(), Date.t()) :: :lt | :eq | :gt
defdelegate point_compare(a, b), to: Date, as: :compare
@spec point_step(Date.t(), integer()) :: Date.t()
def point_step(%Date{} = date, n) when is_integer(n), do: Date.add(date, n)
end
end