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

Link to this function abut?(a, b, opts \\ []) View Source
abut?(Period.t(), Period.t(), keyword()) :: boolean()

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
Link to this function contains?(a, b, opts \\ []) View Source
contains?(Period.t(), Period.t(), keyword()) :: boolean()

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
Link to this function gap(a, b, opts \\ []) View Source
gap(Period.t(), Period.t(), keyword()) :: {:ok, Period.t()} | {:error, binary()}

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>)>
Link to this function intersection(a, b, opts \\ []) View Source
intersection(Period.t(), Period.t(), keyword()) ::
  {:ok, Period.t()} | {:error, binary()}

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>)>
Link to this function is_abutted_left?(a, b, opts \\ []) View Source
is_abutted_left?(Period.t(), Period.t(), keyword()) :: boolean()

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
Link to this function is_abutted_right?(a, b, opts \\ []) View Source
is_abutted_right?(Period.t(), Period.t(), keyword()) :: boolean()

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
Link to this function is_after?(a, b, opts \\ []) View Source
is_after?(Period.t(), Period.t(), keyword()) :: boolean()

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
Link to this function is_before?(a, b, opts \\ []) View Source
is_before?(Period.t(), Period.t(), keyword()) :: boolean()

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
Link to this function is_contained_by?(a, b, opts \\ []) View Source
is_contained_by?(Period.t(), Period.t(), keyword()) :: boolean()

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
Link to this function overlaps?(a, b, opts \\ []) View Source
overlaps?(Period.t(), Period.t(), keyword()) :: boolean()

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
Link to this function same?(a, b, opts \\ []) View Source
same?(Period.t(), Period.t(), keyword()) :: boolean()

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