A recent discussion <https://github.com/elixir-lang/elixir/pull/14162> 
clarified 
that the return value from `Date.day_of_week/2` is an ordinal value. That 
is, when it returns "1" that means "first day of week". It specifically 
does not mean "1" is Monday.  

That means that it would be useful to have a function that does return the 
cardinal day of week - that is, a number where 1 == Monday and 7 == Sunday.

The function would look something like:

def iso_day_of_week(%{calendar: Calendar.ISO} = date) do
  day_of_week(date)
end

def iso_day_of_week(date) do
  date
  |> convert!(Calendar.ISO)
  |> day_of_week()
end

This implementation relies on the knowledge that when called with 
starting_on = :default (which is the default argument value) the returned 
value is indeed 1 == Monday, 7 == Sunday.

If there is any consensus I'll submit a PR.


-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/elixir-lang-core/eeff3e35-448b-4dcf-ad4a-866bac76a819n%40googlegroups.com.

Reply via email to