Date.range
You're seeing just the function
range
, go back to Date module for more information.
Specs
range(Calendar.date(), Calendar.date()) :: Date.Range.t()
Returns a range of dates.
A range of dates represents a discrete number of dates where the first and last values are dates with matching calendars.
Ranges of dates can be either increasing (first <= last
) or
decreasing (first > last
). They are also always inclusive.
Examples
iex> Date.range(~D[1999-01-01], ~D[2000-01-01])
#DateRange<~D[1999-01-01], ~D[2000-01-01]>
A range of dates implements the Enumerable
protocol, which means
functions in the Enum
module can be used to work with
ranges:
iex> range = Date.range(~D[2001-01-01], ~D[2002-01-01])
iex> Enum.count(range)
366
iex> Enum.member?(range, ~D[2001-02-01])
true
iex> Enum.take(range, 3)
[~D[2001-01-01], ~D[2001-01-02], ~D[2001-01-03]]
Specs
range(Calendar.date(), Calendar.date(), step :: pos_integer() | neg_integer()) :: Date.Range.t()
Returns a range of dates with a step.
Examples
iex> range = Date.range(~D[2001-01-01], ~D[2002-01-01], 2)
iex> range
#DateRange<~D[2001-01-01], ~D[2002-01-01], 2>
iex> Enum.count(range)
183
iex> Enum.member?(range, ~D[2001-01-03])
true
iex> Enum.take(range, 3)
[~D[2001-01-01], ~D[2001-01-03], ~D[2001-01-05]]