Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. # ISO Date String to DD/MM/YYYY
  2. def date_to_dd_mm_yyyy(iso_date) do
  3. {_, date} = Date.from_iso8601(iso_date)
  4. {year, month, day} = Date.to_erl(date)
  5.  
  6. Integer.to_string(day) <> "/" <> Integer.to_string(month) <> "/" <> Integer.to_string(year)
  7. end
  8.  
  9. # ISO Time String to 12 hour time
  10. def time_to_12hour(iso_time) do
  11. {:ok, new_time} = Time.from_iso8601(iso_time)
  12. {hour, minute, _second} = Time.to_erl(new_time)
  13.  
  14. minute_string =
  15. cond do
  16. minute < 10 ->
  17. "0" <> Integer.to_string(minute)
  18. true ->
  19. Integer.to_string(minute)
  20. end
  21.  
  22. hour_string =
  23. cond do
  24. hour === 0 ->
  25. "12"
  26. hour > 12 ->
  27. Integer.to_string(hour - 12)
  28. hour <= 12 ->
  29. Integer.to_string(hour)
  30. end
  31.  
  32. meridiem =
  33. cond do
  34. hour >= 12 ->
  35. "pm"
  36. hour < 12 ->
  37. "am"
  38. end
  39.  
  40. hour_string <> ":" <> minute_string <> meridiem
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement