elixirtimex

Using Timex Interval


I've got

Interval.new(from: start_date, until: end_date)

with [start_date, end_date] = [~N[2019-02-12 00:00:00.000000, ~N[2019-02-15 00:00:00.000000]

The problem is, this generates the dates:

[~N[2019-02-12 00:00:00.000000], ~N[2019-02-13 00:00:00.000000],
 ~N[2019-02-14 00:00:00.000000]]

but misses the last day (15th Feb). Is there a way I can coax Timex to adding that boundary to the list?


Solution

  • Timex.Interval.new/1 has a perfect documentation that clearly mentions right_open: true parameter.


    The documentation is not quite accurate though :) It should be right_open: false FWIW.

    [start_date, end_date] =
      [~N[2019-02-12 00:00:00.000000], ~N[2019-02-15 00:00:00.000000]]
    
    Timex.Interval.new(
      from: start_date, until: end_date,
      left_open: false, right_open: false
    )
    |> Enum.to_list
    #⇒ [~N[2019-02-12 00:00:00.000000], ~N[2019-02-13 00:00:00.000000],
    #   ~N[2019-02-14 00:00:00.000000], ~N[2019-02-15 00:00:00.000000]]