View Source Timex.Format.DateTime.Formatters.Relative (timex v3.7.11)

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 secondsnow
1 to 45 secondsa few seconds ago
45 to 90 secondsa minute ago
90 seconds to 45 minutes2 minutes ago ... 45 minutes ago
45 to 90 minutesan hour ago
90 minutes to 22 hours2 hours ago ... 22 hours ago
22 to 36 hoursa day ago
36 hours to 25 days2 days ago ... 25 days ago
25 to 45 daysa month ago
45 to 345 days2 months ago ... 11 months ago
345 to 545 days (1.5 years)a year ago
546 days+2 years ago ... 20 years ago

Link to this section Summary

Link to this section Functions

Link to this function

format!(date, format_string)

View Source
@spec format!(Timex.Types.calendar_types(), String.t()) :: String.t() | no_return()

Callback implementation for Timex.Format.DateTime.Formatter.format!/2.

Link to this function

format(date, format_string)

View Source
@spec format(Timex.Types.calendar_types(), String.t()) ::
  {:ok, String.t()} | {:error, term()}

Formats a date/time as a relative time formatted string

examples

Examples

iex> Elixir.Timex.Format.DateTime.Formatters.Relative.format(Timex.shift(Timex.now, minutes: -1), "{relative}")
{:ok, "1 minute ago"}
Link to this function

lformat!(date, format_string, locale)

View Source

Callback implementation for Timex.Format.DateTime.Formatter.lformat!/3.

Link to this function

lformat(date, format_string, locale)

View Source
@spec lformat(Timex.Types.calendar_types(), String.t(), String.t()) ::
  {:ok, String.t()} | {:error, term()}

Callback implementation for Timex.Format.DateTime.Formatter.lformat/3.

Link to this function

relative_to(date, relative_to, format_string)

View Source
Link to this function

relative_to(date, relative_to, format_string, locale)

View Source
@spec tokenize(String.t()) ::
  {:ok, [Timex.Parse.DateTime.Tokenizers.Directive.t()]} | {:error, term()}

Callback implementation for Timex.Format.DateTime.Formatter.tokenize/1.