Today I learned that Erlang's native calendar
module has a super useful function: last_day_of_the_month/2
! This saved me a ton of work. Here's how you could use it in Elixir:
iex(1)> h :calendar.last_day_of_the_month
:calendar.last_day_of_the_month/2
@spec last_day_of_the_month(year, month) :: lastDay
iex(2)> :calendar.last_day_of_the_month(2020, 2)
29
That's it, short and sweet! Also, since you're here, take a good look at that function name❤️