Skip to main content
edited tags; edited title
Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Can This Function To Generate All Valid Dates In Elixir Be Improved? Generating all valid dates

added 43 characters in body
Source Link

I've come up with the following code to generate a list of all dates between two given dates:

   def generate_all_valid_dates_in_range(_start_date, _end_date) when _start_date <= _end_date do
    (:calendar.date_to_gregorian_days(_start_date) .. :calendar.date_to_gregorian_days(_end_date))
    |> Enum.to_list
    |> Enum.map (&(:calendar.gregorian_days_to_date(&1)))
  end

I would appreciate any comments on style and if there's some built in function (in either Elixir or Erlang) to achieve this sort of functionality.

I've come up with the following code to generate a list of all dates between two given dates:

def generate_all_valid_dates_in_range(_start_date, _end_date) do
  (:calendar.date_to_gregorian_days(_start_date) .. :calendar.date_to_gregorian_days(_end_date))
  |> Enum.to_list
  |> Enum.map (&(:calendar.gregorian_days_to_date(&1)))
end

I would appreciate any comments on style and if there's some built in function (in either Elixir or Erlang) to achieve this sort of functionality.

I've come up with the following code to generate a list of all dates between two given dates:

   def generate_all_valid_dates_in_range(_start_date, _end_date) when _start_date <= _end_date do
    (:calendar.date_to_gregorian_days(_start_date) .. :calendar.date_to_gregorian_days(_end_date))
    |> Enum.to_list
    |> Enum.map (&(:calendar.gregorian_days_to_date(&1)))
  end

I would appreciate any comments on style and if there's some built in function (in either Elixir or Erlang) to achieve this sort of functionality.

Source Link

Can This Function To Generate All Valid Dates In Elixir Be Improved?

I've come up with the following code to generate a list of all dates between two given dates:

def generate_all_valid_dates_in_range(_start_date, _end_date) do
  (:calendar.date_to_gregorian_days(_start_date) .. :calendar.date_to_gregorian_days(_end_date))
  |> Enum.to_list
  |> Enum.map (&(:calendar.gregorian_days_to_date(&1)))
end

I would appreciate any comments on style and if there's some built in function (in either Elixir or Erlang) to achieve this sort of functionality.