You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Recommended way to add ordinal suffix for the day of month? #426
I cannot find the ordinal suffix for the month in the Timex.Format.DateTime.Formatter module. Similar to what PHP has for their datetime:
English ordinal suffix for the day of the month, 2 characters | st, nd, rd or th. http://php.net/manual/en/function.date.php
Is a custom formatter recommended to add the suffix?
Reacted by Jonathan Yankovich, Aaron Ross, Darragh Enright, David Webster and Jonathan Balls
For now I created this module to get the suffix and then I put the result in the Timex.format call.
defmodule OrdinalSuffix do
def get(i) do
value = elem(Integer.parse(i), 0)
j = div(value, 10)
k = div(value, 100)
cond do
j == 1 && k != 11 ->
"st"
j == 2 && k != 12 ->
"nd"
j == 3 && k != 13 ->
"rd"
true ->
"th"
end
end
end
Activity
najicham commentedon Apr 7, 2018
For now I created this module to get the suffix and then I put the result in the Timex.format call.
I call it with this:
bitwalker commentedon May 8, 2018
I'm open to extending the formatter with a new token, if you would like to submit a PR!