momento v0.1.2 Momento

Momento is an Elixir port of Moment.js for the purpose of parsing, validating, manipulating, and formatting dates.

Summary

Functions

Add a specified amount of time to a given DateTime struct

Provides a DateTime struct representing the current date and time

Provides a DateTime struct from any recognizeable form of input, such as an ISO string or UNIX timestamp

Shortcut to get a DateTime struct representing now

Provides a DateTime struct from any recognizeable form of input, such as an ISO string or UNIX timestamp

Format a given DateTime struct to a desired date string

Subtract a specified amount of time to a given DateTime struct

Functions

add(datetime, num, time)

Specs

add(DateTime.t, integer, atom) :: DateTime.t

Add a specified amount of time to a given DateTime struct.

Examples

iex> Momento.date! |> Momento.add(2, :years)
%DateTime{calendar: Calendar.ISO, day: 1, hour: 21, microsecond: {796482, 6},
 minute: 38, month: 7, second: 18, std_offset: 0, time_zone: "Etc/UTC",
 utc_offset: 0, year: 2018, zone_abbr: "UTC"}
date()

Specs

date :: {:ok, DateTime.t}

Provides a DateTime struct representing the current date and time.

Examples

iex> Momento.date
{:ok,
 %DateTime{calendar: Calendar.ISO, day: 1, hour: 21, microsecond: {827272, 6},
  minute: 27, month: 7, second: 19, std_offset: 0, time_zone: "Etc/UTC",
  utc_offset: 0, year: 2016, zone_abbr: "UTC"}}
date(arg)

Specs

date(any) :: {:ok, DateTime.t}

Provides a DateTime struct from any recognizeable form of input, such as an ISO string or UNIX timestamp.

Examples

Momento.date
{:ok,
 %DateTime{calendar: Calendar.ISO, day: 1, hour: 21, microsecond: {827272, 6},
  minute: 27, month: 7, second: 19, std_offset: 0, time_zone: "Etc/UTC",
  utc_offset: 0, year: 2016, zone_abbr: "UTC"}}
date!()

Specs

date! :: DateTime.t

Shortcut to get a DateTime struct representing now.

Examples

iex> Momento.date!
%DateTime{calendar: Calendar.ISO, day: 1, hour: 21, microsecond: {0, 0},
 minute: 32, month: 7, second: 15, std_offset: 0, time_zone: "Etc/UTC",
 utc_offset: 0, year: 2016, zone_abbr: "UTC"}
date!(arg)

Specs

date!(any) :: DateTime.t

Provides a DateTime struct from any recognizeable form of input, such as an ISO string or UNIX timestamp.

Examples

iex> Momento.date!(1467408735)
%DateTime{calendar: Calendar.ISO, day: 1, hour: 21, microsecond: {0, 0},
 minute: 32, month: 7, second: 15, std_offset: 0, time_zone: "Etc/UTC",
 utc_offset: 0, year: 2016, zone_abbr: "UTC"}
format(datetime, tokens)

Specs

Format a given DateTime struct to a desired date string.

Examples

iex> Momento.date! |> Momento.format("YYYY-MM-DD")
"2016-07-01"
subtract(datetime, num, time)

Specs

subtract(DateTime.t, integer, atom) :: DateTime.t

Subtract a specified amount of time to a given DateTime struct.

Examples

iex> Momento.date! |> Momento.subtract(2, :years)
%DateTime{calendar: Calendar.ISO, day: 1, hour: 21, microsecond: {19292, 6},
 minute: 39, month: 7, second: 11, std_offset: 0, time_zone: "Etc/UTC",
 utc_offset: 0, year: 2014, zone_abbr: "UTC"}