DateTime.Extension (ESpec v1.10.0)

View Source

A module to extend the calendar implementation that follows to ISO8601 with methods found in Elixir 1.5.1. This is to allow ESpec to support Elixir >= 1.3.4 more easily.

Summary

Types

t()

@type t() :: %DateTime.Extension{
  calendar: Calendar.calendar(),
  day: Calendar.day(),
  hour: Calendar.hour(),
  microsecond: Calendar.microsecond(),
  minute: Calendar.minute(),
  month: Calendar.month(),
  second: Calendar.second(),
  std_offset: Calendar.std_offset(),
  time_zone: Calendar.time_zone(),
  utc_offset: Calendar.utc_offset(),
  year: Calendar.year(),
  zone_abbr: Calendar.zone_abbr()
}

Functions

from_naive(naive_datetime, time_zone)

@spec from_naive(NaiveDateTime.t(), Calendar.time_zone()) :: {:ok, t()}

Converts the given NaiveDateTime to DateTime.

It expects a time zone to put the NaiveDateTime in. Currently it only supports "Etc/UTC" as time zone.

Examples

iex> {:ok, datetime} = DateTime.from_naive(~N[2016-05-24 13:26:08.003], "Etc/UTC")
iex> datetime
#DateTime<2016-05-24 13:26:08.003Z>

from_naive!(naive_datetime, time_zone)

@spec from_naive!(NaiveDateTime.t(), Calendar.time_zone()) :: t()

Converts the given NaiveDateTime to DateTime.

It expects a time zone to put the NaiveDateTime in. Currently it only supports "Etc/UTC" as time zone.

Examples

iex> DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC")
#DateTime<2016-05-24 13:26:08.003Z>