Timex.DateFormat.Formatters.Formatter behaviour

Summary

format!(date, format_string, formatter \\ Timex.DateFormat.Formatters.DefaultFormatter)

Formats a DateTime struct as a string, using the provided format string and formatter. If a formatter is not provided, the formatter used is Timex.DateFormat.Formatters.DefaultFormatter

format(date, format_string, formatter \\ Timex.DateFormat.Formatters.DefaultFormatter)

Formats a DateTime struct as a string, using the provided format string and formatter. If a formatter is not provided, the formatter used is Timex.DateFormat.Formatters.DefaultFormatter

format_token(token, date)

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

validate(format_string, formatter \\ Timex.DateFormat.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

Functions

format(date, format_string, formatter \\ Timex.DateFormat.Formatters.DefaultFormatter)

Specs:

  • format(%Timex.DateTime{calendar: term, day: term, hour: term, minute: term, month: term, ms: term, second: term, timezone: term, year: term}, String.t, Timex.DateFormat.Formatters.Formatter | nil) :: {:ok, String.t} | {:error, term}

Formats a DateTime struct as a string, using the provided format string and formatter. If a formatter is not provided, the formatter used is Timex.DateFormat.Formatters.DefaultFormatter.

format!(date, format_string, formatter \\ Timex.DateFormat.Formatters.DefaultFormatter)

Specs:

  • format!(%Timex.DateTime{calendar: term, day: term, hour: term, minute: term, month: term, ms: term, second: term, timezone: term, year: term}, String.t, Timex.DateFormat.Formatters.Formatter | nil) :: String.t | no_return

Formats a DateTime struct as a string, using the provided format string and formatter. If a formatter is not provided, the formatter used is Timex.DateFormat.Formatters.DefaultFormatter.

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

format_token(token, date)

Specs:

  • format_token(atom, %Timex.DateTime{calendar: term, day: term, hour: term, minute: term, month: term, ms: term, second: term, timezone: term, year: term}) :: String.t

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

validate(format_string, formatter \\ Timex.DateFormat.Formatters.DefaultFormatter)

Specs:

  • validate(String.t, Timex.DateFormat.Formatters.Formatter | 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.

Callbacks

format/2

Specs:

  • format(date :: %Timex.DateTime{calendar: term, day: term, hour: term, minute: term, month: term, ms: term, second: term, timezone: term, year: term}, format_string :: String.t) :: {:ok, String.t} | {:error, term}
format!/2

Specs:

  • format!(date :: %Timex.DateTime{calendar: term, day: term, hour: term, minute: term, month: term, ms: term, second: term, timezone: term, year: term}, format_string :: String.t) :: String.t | no_return
tokenize/1

Specs:

  • tokenize(format_string :: String.t) :: {:ok, [%Timex.Parsers.DateFormat.Directive{format: term, len: term, match: term, max: term, min: term, optional: term, pad: term, pad_type: term, raw: term, token: term, type: term, validate: term}]} | {:error, term}