elixirtimex

Generate a list of dates


Let's say I'm using Timex as follows:

use Timex
Interval.new(from: ~D[2016-03-03], until: [days: 3])
%Elixir.Timex.Interval{from: ~N[2016-03-03 00:00:00], left_open: false, right_open: true, step: [days: 1], until: ~N[2016-03-06 00:00:00]}

I want to generate a list of dates, one day apart. How do I go from this to a list?


Solution

  • Why would you use 3rd party libraries like Timex for such a simple thing?

    Enum.map(0..3, &Date.add(~D[2016-03-03], &1))
    #⇒ [~D[2016-03-03], ~D[2016-03-04], ~D[2016-03-05], ~D[2016-03-06]]