26 lines
868 B
Plaintext
26 lines
868 B
Plaintext
defmodule Date do
|
|
def iso_date, do: iso_date(:erlang.date)
|
|
|
|
def iso_date(year, month, day), do: iso_date({year, month, day})
|
|
|
|
def iso_date(date), do:
|
|
:io.format("~4b-~2..0B-~2..0B~n", Tuple.to_list(date))
|
|
|
|
def long_date, do: long_date(:erlang.date)
|
|
|
|
def long_date(year, month, day), do: long_date({year, month, day})
|
|
|
|
def long_date(date = {year, month, day}) do
|
|
months = { "January", "February", "March", "April", "May", "June",
|
|
"July", "August", "September", "October", "November", "December" }
|
|
weekdays = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }
|
|
weekday = :calendar.day_of_the_week(date)
|
|
IO.puts "#{elem(weekdays, weekday-1)}, #{elem(months, month-1)} #{day}, #{year}"
|
|
end
|
|
end
|
|
|
|
Date.iso_date
|
|
Date.iso_date(2007,11,10)
|
|
Date.long_date
|
|
Date.long_date(2007,11,10)
|