Timex.DateFormat.Formatters.DefaultFormatter

Date formatting language used by default by the DateFormat module.

This is a novel formatting language introduced with DateFormat. Its main advantage is simplicity and usage of mnemonics that are easy to memorize.

Directive format

A directive is an optional padding specifier followed by a mnemonic, both enclosed in braces ({ and }):

{<padding><mnemonic>}

Supported padding specifiers:

When padding specifier is omitted, numbers will not be padded.

List of all directives

Years and centuries

Months

Days and weekdays

Weeks

Time

Time zones

Compound directives

These are shortcut directives corresponding to parts of the ISO 8601 specification. The benefit of using these over manually constructed ISO formats is that these directives convert the date to UTC for you.

These directives provide support for miscellaneous common formats:

Summary

format!(date, format_string)

Callback implementation for Timex.DateFormat.Formatters.Formatter.format!/2

format(date, format_string)

Callback implementation for Timex.DateFormat.Formatters.Formatter.format/2

format(date, format_string, tokenizer)

If one wants to use the default formatting semantics with a different tokenizer, this is the way

tokenize(format_string)

Callback implementation for Timex.DateFormat.Formatters.Formatter.tokenize/1

Functions

format(date, format_string)

Specs:

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

Callback implementation for Timex.DateFormat.Formatters.Formatter.format/2.

format(date, format_string, tokenizer)

Specs:

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

If one wants to use the default formatting semantics with a different tokenizer, this is the way.

format!(date, format_string)

Specs:

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

Callback implementation for Timex.DateFormat.Formatters.Formatter.format!/2.

tokenize(format_string)

Specs:

  • tokenize(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}

Callback implementation for Timex.DateFormat.Formatters.Formatter.tokenize/1.