View Source Cocktail.Span (Cocktail v0.10.3)
Struct used to represent a span of time.
It is composed of the following fields:
- from: the start time of the span
- until: the end time of the span
When expanding a Cocktail.Schedule.t/0
, if it has a duration it will
produce a list of t/0
instead of a list of Cocktail.time/0
.
Link to this section Summary
Functions
Uses Timex.compare/2
to determine which span comes first.
Creates a new t/0
from the given start time and end time.
Returns an overlap_mode/0
to describe how the first span overlaps the second.
Link to this section Types
@type overlap_mode() ::
:contains
| :is_inside
| :is_before
| :is_after
| :is_equal_to
| :overlaps_the_start_of
| :overlaps_the_end_of
@type span_compat() :: %{ :from => Cocktail.time(), :until => Cocktail.time(), optional(atom()) => any() }
@type t() :: %Cocktail.Span{from: Cocktail.time(), until: Cocktail.time()}
Link to this section Functions
@spec compare(span_compat(), span_compat()) :: Timex.Comparable.compare_result()
Uses Timex.compare/2
to determine which span comes first.
Compares from
first, then, if equal, compares until
.
examples
Examples
iex> span1 = new(~N[2017-01-01 06:00:00], ~N[2017-01-01 10:00:00])
...> span2 = new(~N[2017-01-01 06:00:00], ~N[2017-01-01 10:00:00])
...> compare(span1, span2)
0
iex> span1 = new(~N[2017-01-01 06:00:00], ~N[2017-01-01 10:00:00])
...> span2 = new(~N[2017-01-01 07:00:00], ~N[2017-01-01 12:00:00])
...> compare(span1, span2)
-1
iex> span1 = new(~N[2017-01-01 06:00:00], ~N[2017-01-01 10:00:00])
...> span2 = new(~N[2017-01-01 06:00:00], ~N[2017-01-01 07:00:00])
...> compare(span1, span2)
1
@spec new(Cocktail.time(), Cocktail.time()) :: t()
Creates a new t/0
from the given start time and end time.
examples
Examples
iex> new(~N[2017-01-01 06:00:00], ~N[2017-01-01 10:00:00])
%Cocktail.Span{from: ~N[2017-01-01 06:00:00], until: ~N[2017-01-01 10:00:00]}
@spec overlap_mode(span_compat(), span_compat()) :: overlap_mode()
Returns an overlap_mode/0
to describe how the first span overlaps the second.
examples
Examples
iex> span1 = new(~N[2017-01-01 06:00:00], ~N[2017-01-01 10:00:00])
...> span2 = new(~N[2017-01-01 06:00:00], ~N[2017-01-01 10:00:00])
...> overlap_mode(span1, span2)
:is_equal_to
iex> span1 = new(~N[2017-01-01 06:00:00], ~N[2017-01-01 10:00:00])
...> span2 = new(~N[2017-01-01 07:00:00], ~N[2017-01-01 09:00:00])
...> overlap_mode(span1, span2)
:contains
iex> span1 = new(~N[2017-01-01 07:00:00], ~N[2017-01-01 09:00:00])
...> span2 = new(~N[2017-01-01 06:00:00], ~N[2017-01-01 10:00:00])
...> overlap_mode(span1, span2)
:is_inside
iex> span1 = new(~N[2017-01-01 06:00:00], ~N[2017-01-01 07:00:00])
...> span2 = new(~N[2017-01-01 09:00:00], ~N[2017-01-01 10:00:00])
...> overlap_mode(span1, span2)
:is_before