Cocktail v0.5.2 Cocktail.Span View Source
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
Link to this type
overlap_mode()
View Source
overlap_mode :: :contains | :is_inside | :is_before | :is_after | :overlaps_the_start_of | :overlaps_the_end_of
Link to this section Functions
Link to this function
compare(span1, span2)
View Source
compare(t, t) :: Timex.Comparable.compare_result
Uses Timex.compare/2
to determine which span comes first.
Compares from
first, then, if equal, compares until
.
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
Creates a new t/0
from the given start time and end time.
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]}
Returns an overlap_mode/0
to describe how the first span overlaps the second.
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