Timex.Format.DateTime.Formatters.Relative (timex v3.7.13)

View Source

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

Summary

Functions

format(date, format_string)

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

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), "{relative}")
{:ok, "1 minute ago"}

format!(date, format_string)

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

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

lformat(date, format_string, locale)

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

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

lformat!(date, format_string, locale)

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

relative_to(date, relative_to, format_string)

relative_to(date, relative_to, format_string, locale)

tokenize(format_string)

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

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