timex v2.1.1 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 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)

Specs

format(Timex.DateTime.t, String.t) ::
  {:ok, String.t} |
  {:error, term}

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

format!(date, format_string)

Specs

format!(Timex.DateTime.t, String.t) ::
  String.t |
  no_return

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

lformat(date, format_string, locale)

Specs

lformat(Timex.DateTime.t, String.t, String.t) ::
  String.t |
  no_return
lformat(Timex.DateTime.t, 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)

Specs

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

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