timex v3.0.6 Timex.Format.DateTime.Formatters.Relative
Relative time, based on Moment.js
Uses localized strings.
The format string should contain {relative}, which is where the phrase will be injected.
| Range | Sample Output
0 seconds | now | |
1 to 45 seconds | a few seconds ago | |
45 to 90 seconds | a minute ago | |
90 seconds to 45 minutes | 2 minutes ago … 45 minutes ago | |
45 to 90 minutes | an hour ago | |
90 minutes to 22 hours | 2 hours ago … 22 hours ago | |
22 to 36 hours | a day ago | |
36 hours to 25 days | 2 days ago … 25 days ago | |
25 to 45 days | a month ago | |
45 to 345 days | 2 months ago … 11 months ago |
| 345 to 545 days (1.5 years)| a year ago | 546 days+ | 2 years ago … 20 years ago
Summary
Functions
Formats a date/time as a relative time formatted string
Callback implementation for Timex.Format.DateTime.Formatter.format!/2
Callback implementation for Timex.Format.DateTime.Formatter.lformat/3
Callback implementation for Timex.Format.DateTime.Formatter.lformat!/3
Callback implementation for Timex.Format.DateTime.Formatter.tokenize/1
Functions
Formats a date/time as a relative time formatted string
Examples
iex> Elixir.Timex.Format.DateTime.Formatters.Relative.format(Timex.shift(Timex.now, minutes: -1))
"1 minute ago"
Callback implementation for Timex.Format.DateTime.Formatter.format!/2
.
Specs
Callback implementation for Timex.Format.DateTime.Formatter.lformat/3
.
Callback implementation for Timex.Format.DateTime.Formatter.lformat!/3
.
Specs
tokenize(String.t) ::
{:ok, [Timex.Parse.DateTime.Tokenizers.Directive.t]} |
{:error, term}
Callback implementation for Timex.Format.DateTime.Formatter.tokenize/1
.