timex v2.1.1 Timex.Convertable protocol

This protocol is used to convert between various common datetime formats.

Summary

Functions

Converts a date/time representation to a Date struct

Converts a date/time representation to a DateTime struct

Converts a date/time representation to an Erlang datetime tuple

Converts a date/time representation to an Erlang datetime tuple + timezone tuple

Converts a date/time representation to the number of seconds since the start of year zero of the Gregorian calendar

Converts a date/time representation to a Julian date number

Converts a date/time representation to an Erlang timestamp tuple, relative to the UNIX epoch

Converts a date/time representation to a UNIX timestamp (i.e. seconds since UNIX epoch) Returns {:error, :not_representable} if the date/time occurs before the UNIX epoch

Types

t :: term

Functions

to_date(date)

Converts a date/time representation to a Date struct

Examples:

iex> use Timex
...> Timex.to_date({{2015, 3, 5}, {12, 0, 0}})
%Timex.Date{:year => 2015, :month => 3, :day => 5}
to_datetime(date)

Converts a date/time representation to a DateTime struct

Examples:

iex> use Timex
...> Timex.to_date({{2015, 3, 5}, {12, 0, 0}})
%Timex.Date{:year => 2015, :month => 3, :day => 5}
to_erlang_datetime(date)

Converts a date/time representation to an Erlang datetime tuple

Examples:

iex> use Timex
...> datetime = Timex.datetime({{2015, 3, 5}, {12, 0, 0}}, "America/Chicago")
...> Timex.to_erlang_datetime(datetime)
{{2015, 3, 5}, {12, 0, 0}}
to_gregorian(date)

Converts a date/time representation to an Erlang datetime tuple + timezone tuple

Examples:

iex> use Timex
...> datetime = Timex.datetime({{2015, 3, 5}, {12, 0, 0}}, "America/Chicago")
...> Timex.to_gregorian(datetime)
{{2015, 3, 5}, {12, 0, 0}, {6, "CST"}}
to_gregorian_seconds(date)

Converts a date/time representation to the number of seconds since the start of year zero of the Gregorian calendar.

Examples:

iex> use Timex
...> Timex.to_gregorian_seconds({{2015, 3, 5}, {12, 0, 0}})
63592776000
to_julian(date)

Converts a date/time representation to a Julian date number

Examples:

iex> use Timex
...> Timex.to_julian({{2016,3,9}, {11,0,0}})
2457457.4
to_timestamp(date)

Converts a date/time representation to an Erlang timestamp tuple, relative to the UNIX epoch

Examples:

iex> use Timex …> Timex.to_timestamp({{2015, 3, 5}, {12, 0, 0}}) {1425, 556800, 0}

to_unix(date)

Converts a date/time representation to a UNIX timestamp (i.e. seconds since UNIX epoch) Returns {:error, :not_representable} if the date/time occurs before the UNIX epoch

Examples:

iex> use Timex
...> Timex.to_unix({{2015, 3, 5}, {12, 0, 0}})
1425556800