Timex.DateFormat

Date formatting and parsing.

This module provides an interface and core implementation for converting date values into strings (formatting) or the other way around (parsing) according to the specified template.

Multiple template formats are supported, each one provided by a separate module. One can also implement custom formatters for use with this module.

Summary

format!(date, format_string)

Raising version of format/2. Returns a string with formatted date or raises a FormatError

format!(date, format_string, formatter)

Raising version of format/3. Returns a string with formatted date or raises a FormatError

format(date, format_string)

Converts date values to strings according to the given template (aka format string)

format(date, format_string, formatter)

Same as format/2, but takes a custom formatter

parse!(date_string, format_string)

Raising version of parse/2. Returns a DateTime struct, or raises a ParseError

parse!(date_string, format_string, parser)

Raising version of parse/3. Returns a DateTime struct, or raises a ParseError

parse(date_string, format_string)

Parses the date encoded in string according to the template

parse(date_string, format_string, parser)

Parses the date encoded in string according to the template by using the provided formatter

validate(format_string, formatter \\ nil)

Verifies the validity of the given format string according to the provided formatter, defaults to the Default formatter if one is not provided

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, String.t}

Converts date values to strings according to the given template (aka format string).

format(date, format_string, formatter)

Specs:

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

Same as format/2, but takes a custom formatter.

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

Raising version of format/2. Returns a string with formatted date or raises a FormatError.

format!(date, format_string, formatter)

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) :: String.t | no_return

Raising version of format/3. Returns a string with formatted date or raises a FormatError.

parse(date_string, format_string)

Specs:

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

Parses the date encoded in string according to the template.

parse(date_string, format_string, parser)

Specs:

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

Parses the date encoded in string according to the template by using the provided formatter.

parse!(date_string, format_string)

Specs:

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

Raising version of parse/2. Returns a DateTime struct, or raises a ParseError.

parse!(date_string, format_string, parser)

Specs:

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

Raising version of parse/3. Returns a DateTime struct, or raises a ParseError.

validate(format_string, formatter \\ nil)

Specs:

  • validate(String.t, atom) :: :ok | {:error, term}

Verifies the validity of the given format string according to the provided formatter, defaults to the Default formatter if one is not provided.

Returns :ok if the format string is clean, { :error, <reason> } otherwise.