Period v0.1.0 Period.Relationship View Source
Does work with relationships between two Period’s.
Link to this section Summary
Functions
Determine if the periods abut each other
Determine if the first period contains the second one
If both periods do not overlap or abut it returns a new period of the gap between both
If both periods overlap returns a new period of the intersection of both
Determine if the first period is abutted on it’s left side by the second period
Determine if the first period is abutted on it’s right side by the second period
Determine if the first period is after the second one
Determine if the first period is before the second one
Determine if the first period is contained by the second one
Determine if the first period overlaps the second one
Determine if both periods span the same time
Link to this section Functions
Determine if the periods abut each other.
Being about means having no overlap, but having no gap:
End exclusive - Start inclusive
… . . .)
[. . . …
End inclusive - Start exclusive
… . . .]
(. . . …
Both inclusive
… . .]
[. . . …
Examples
iex> a = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-21 10:29:12])
iex> b = Period.from_naive!(~N[2017-11-21 10:29:12], ~N[2017-11-23 10:29:12])
iex> Period.Relationship.abut?(a, b) && Period.Relationship.abut?(b, a)
true
Determine if the first period contains the second one.
Containment means having being at least the same period as the second one, but overlaping it on at least one side:
Overlap both ends
[. . . . . . .]
[. . . . .]
Overlap start
[. . . . . . .]
[. . . . . .]
Overlap end
[. . . . . . .]
[. . . . . .]
Examples
iex> a = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-22 14:32:21])
iex> b = Period.from_naive!(~N[2017-11-20 18:32:21], ~N[2017-11-22 07:32:21])
iex> Period.Relationship.contains?(a, b)
true
If both periods do not overlap or abut it returns a new period of the gap between both.
For details on what overlapping means, see: overlaps?/3. For details on what abut means, see: abut?/3.
Examples
iex> a = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-21 10:29:12])
iex> b = Period.from_naive!(~N[2017-11-22 14:32:21], ~N[2017-11-23 10:29:12])
iex> Period.Relationship.gap(a, b)
iex> {:ok, period} = Period.Relationship.gap(a, b)
iex> period
#Period<[#DateTime<2017-11-21 10:29:12.000000Z>, #DateTime<2017-11-22 14:32:21.000000Z>)>
If both periods overlap returns a new period of the intersection of both.
For details on what overlapping means, see: overlaps?/3.
Examples
iex> a = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-22 14:32:21])
iex> b = Period.from_naive!(~N[2017-11-21 10:29:12], ~N[2017-11-23 10:29:12])
iex> {:ok, period} = Period.Relationship.intersection(a, b)
iex> period
#Period<[#DateTime<2017-11-21 10:29:12.000000Z>, #DateTime<2017-11-22 14:32:21.000000Z>)>
Determine if the first period is abutted on it’s left side by the second period.
For details on what abut means, see: abut?/3.
Examples
iex> a = Period.from_naive!(~N[2017-11-21 10:29:12], ~N[2017-11-23 10:29:12])
iex> b = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-21 10:29:12])
iex> Period.Relationship.is_abutted_left?(a, b)
true
Determine if the first period is abutted on it’s right side by the second period.
For details on what abut means, see: abut?/3.
Examples
iex> a = Period.from_naive!(~N[2017-11-21 10:29:12], ~N[2017-11-23 10:29:12])
iex> b = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-21 10:29:12])
iex> Period.Relationship.is_abutted_right?(b, a)
true
Determine if the first period is after the second one.
Being after the other period means having no overlap, but the periods might directly abut each other.
Examples
iex> a = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-21 10:29:12])
iex> b = Period.from_naive!(~N[2017-11-22 14:32:21], ~N[2017-11-23 10:29:12])
iex> Period.Relationship.is_after?(b, a)
true
Determine if the first period is before the second one.
Being before the other period means having no overlap, but the periods might directly abut each other.
Examples
iex> a = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-21 10:29:12])
iex> b = Period.from_naive!(~N[2017-11-22 14:32:21], ~N[2017-11-23 10:29:12])
iex> Period.Relationship.is_before?(a, b)
true
Determine if the first period is contained by the second one.
For details on what contained means, see: contains?/3.
## Examples
iex> a = Period.from_naive!(~N[2017-11-20 18:32:21], ~N[2017-11-22 07:32:21])
iex> b = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-22 14:32:21])
iex> Period.Relationship.is_contained_by?(a, b)
true
Determine if the first period overlaps the second one.
Overlaping means having being at least one common point:
End exclusive - Start inclusive
… . . .)
[. . . . …
End inclusive - Start exclusive
… . . .]
(. . . . …
Both inclusive
… . .]
[. . . . …
Both exclusive
… . . . .)
(. . . . …
Examples
iex> a = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-22 14:32:21])
iex> b = Period.from_naive!(~N[2017-11-21 10:29:12], ~N[2017-11-23 10:29:12])
iex> Period.Relationship.overlaps?(a, b)
true
Determine if both periods span the same time.
Non-strict comparison
Simple
[. . . . .]
[. . . . .]
Exclusive overlap start
(. . . . . . .]
[. . . . . .]
Exclusive overlap end
[. . . . . . .)
[. . . . . .]
Strict comparison
For strict comparison timespan and boundry states need to be the same.
Examples
iex> a = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-22 14:32:21])
iex> b = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-22 14:32:21])
iex> Period.Relationship.same?(a, b)
true
iex> a = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-22 14:32:21])
iex> b = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-22 14:32:21])
iex> Period.Relationship.same?(a, b, strict: true)
true
iex> a = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-22 14:32:21.000001])
iex> b = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-22 14:32:21], upper_state: :included)
iex> Period.Relationship.same?(a, b)
true
iex> a = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-22 14:32:21.000001])
iex> b = Period.from_naive!(~N[2017-11-20 14:32:21], ~N[2017-11-22 14:32:21], upper_state: :included)
iex> Period.Relationship.same?(a, b, strict: true)
false