timex v3.1.21 Timex.Format.DateTime.Formatter behaviour View Source

This module defines the behaviour for custom DateTime formatters.

Link to this section Summary

Functions

Formats a Date, DateTime, or NaiveDateTime as a string, using the provided format string and formatter. If a formatter is not provided, the formatter used is Timex.Format.DateTime.Formatters.DefaultFormatter

Formats a Date, DateTime, or NaiveDateTime as a string, using the provided format string and formatter. If a formatter is not provided, the formatter used is Timex.Format.DateTime.Formatters.DefaultFormatter

Given a token (as found in Timex.Parsers.Directive), and a Date, DateTime, or NaiveDateTime struct, produce a string representation of the token using values from the struct, using the default locale

Given a token (as found in Timex.Parsers.Directive), and a Date, DateTime, or NaiveDateTime struct, produce a string representation of the token using values from the struct

Formats a Date, DateTime, or NaiveDateTime as a string, using the provided format string, locale, and formatter. If the locale provided does not have translations, “en” is used by default. If a formatter is not provided, the formatter used is Timex.Format.DateTime.Formatters.DefaultFormatter

Formats a Date, DateTime, or NaiveDateTime as a string, using the provided format string, locale, and formatter. If the locale does not have translations, “en” will be used by default. If a formatter is not provided, the formatter used is Timex.Format.DateTime.Formatters.DefaultFormatter

Validates the provided format string, using the provided formatter, or if none is provided, the default formatter. Returns :ok when valid, or {:error, reason} if not valid

Link to this section Functions

Link to this function format(date, format_string, formatter \\ Default) View Source
format(Timex.Types.calendar_types, String.t, atom | nil) ::
  {:ok, String.t} |
  {:error, term}

Formats a Date, DateTime, or NaiveDateTime as a string, using the provided format string and formatter. If a formatter is not provided, the formatter used is Timex.Format.DateTime.Formatters.DefaultFormatter.

Formatting will use the configured default locale, “en” if no other default is given.

Link to this function format!(date, format_string, formatter \\ Default) View Source
format!(Timex.Types.calendar_types, String.t, atom | nil) ::
  String.t |
  no_return

Formats a Date, DateTime, or NaiveDateTime as a string, using the provided format string and formatter. If a formatter is not provided, the formatter used is Timex.Format.DateTime.Formatters.DefaultFormatter.

Formatting will use the configured default locale, “en” if no other default is given.

If an error is encountered during formatting, format! will raise.

Link to this function format_token(token, date, modifiers, flags, width) View Source
format_token(atom, Timex.Types.calendar_types, list, list, list) ::
  String.t |
  {:error, term}

Given a token (as found in Timex.Parsers.Directive), and a Date, DateTime, or NaiveDateTime struct, produce a string representation of the token using values from the struct, using the default locale.

Link to this function format_token(locale, token, date, modifiers, flags, width) View Source
format_token(String.t, atom, Timex.Types.calendar_types, list, list, list) ::
  String.t |
  {:error, term}

Given a token (as found in Timex.Parsers.Directive), and a Date, DateTime, or NaiveDateTime struct, produce a string representation of the token using values from the struct.

Link to this function lformat(date, format_string, locale, formatter \\ Default) View Source
lformat(Timex.Types.calendar_types, String.t, String.t, atom | nil) ::
  {:ok, String.t} |
  {:error, term}

Formats a Date, DateTime, or NaiveDateTime as a string, using the provided format string, locale, and formatter. If the locale provided does not have translations, “en” is used by default. If a formatter is not provided, the formatter used is Timex.Format.DateTime.Formatters.DefaultFormatter

Link to this function lformat!(date, format_string, locale, formatter \\ Default) View Source
lformat!(Timex.Types.calendar_types, String.t, String.t, atom | nil) ::
  String.t |
  no_return

Formats a Date, DateTime, or NaiveDateTime as a string, using the provided format string, locale, and formatter. If the locale does not have translations, “en” will be used by default. If a formatter is not provided, the formatter used is Timex.Format.DateTime.Formatters.DefaultFormatter

If an error is encountered during formatting, lformat! will raise

Link to this function validate(format_string, formatter \\ Default) View Source
validate(String.t, atom | nil) :: :ok | {:error, term}

Validates the provided format string, using the provided formatter, or if none is provided, the default formatter. Returns :ok when valid, or {:error, reason} if not valid.

Link to this section Callbacks

Link to this callback format(date, format_string) View Source
format(date :: Timex.Types.calendar_types, format_string :: String.t) ::
  {:ok, String.t} |
  {:error, term}
Link to this callback format!(date, format_string) View Source
format!(date :: Timex.Types.calendar_types, format_string :: String.t) ::
  String.t |
  no_return
Link to this callback lformat(date, format_string, locale) View Source
lformat(date :: Timex.Types.calendar_types, format_string :: String.t, locale :: String.t) ::
  {:ok, String.t} |
  {:error, term}
Link to this callback lformat!(date, format_string, locale) View Source
lformat!(date :: Timex.Types.calendar_types, format_string :: String.t, locale :: String.t) ::
  String.t |
  no_return
Link to this callback tokenize(format_string) View Source
tokenize(format_string :: String.t) ::
  {:ok, [Timex.Parse.DateTime.Tokenizers.Directive.t]} |
  {:error, term}