I want to create a list of dates with the values from startdate to enddate
This is something similar to How to create a range of dates in R but in Elixir.
Since the list can be huge or sometime infinite (i.e., no end date), I want to also know how to create a stream of dates.
start_date = Calendar.Date.from_erl!({2014,12,27})
date_stream = Stream.iterate(start_date, &(Calendar.Date.next_day!(&1)))
Enum.take(date_stream, 10)
#=>
[%Calendar.Date{day: 27, month: 12, year: 2014},
%Calendar.Date{day: 28, month: 12, year: 2014},
%Calendar.Date{day: 29, month: 12, year: 2014},
%Calendar.Date{day: 30, month: 12, year: 2014},
%Calendar.Date{day: 31, month: 12, year: 2014},
%Calendar.Date{day: 1, month: 1, year: 2015},
%Calendar.Date{day: 2, month: 1, year: 2015},
%Calendar.Date{day: 3, month: 1, year: 2015},
%Calendar.Date{day: 4, month: 1, year: 2015},
%Calendar.Date{day: 5, month: 1, year: 2015}]
thanks José Valim for pointing at right direction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With