Kalends.NaiveDateTime
NaiveDateTime can represents a "naive time". That is a point in time without a specified time zone.
Summary
from_erl!(erl_date_time, frac_sec \\ nil) | Like from_erl/1 without "!", but returns the result directly without a tag. Will raise if date is invalid. Only use this if you are sure the date is valid |
from_erl(arg1, frac_sec \\ nil) | Takes an Erlang-style date-time tuple. If the datetime is valid it returns a tuple with a tag and a naive DateTime. Naive in this context means that it does not have any timezone data |
strftime!(ndt, string, lang \\ :en) | Like DateTime.Format.strftime! but for NaiveDateTime |
to_date(dt) | Takes a NaiveDateTime struct and returns a Date struct representing the date part of the provided NaiveDateTime |
to_date_time(ndt, timezone) | For turning NaiveDateTime structs to into a DateTime |
to_date_time_utc(ndt) | Promote to DateTime with UTC time zone |
to_erl(naivedatetime) | Takes a NaiveDateTime struct and returns an erlang style datetime tuple |
to_time(dt) | Takes a NaiveDateTime struct and returns a Time struct representing the time part of the provided NaiveDateTime |
Functions
Takes an Erlang-style date-time tuple. If the datetime is valid it returns a tuple with a tag and a naive DateTime. Naive in this context means that it does not have any timezone data.
Examples
iex>from_erl({{2014, 9, 26}, {17, 10, 20}})
{:ok, %Kalends.NaiveDateTime{day: 26, hour: 17, min: 10, month: 9, sec: 20, year: 2014} }
iex>from_erl({{2014, 9, 26}, {17, 10, 20}}, 0.321)
{:ok, %Kalends.NaiveDateTime{day: 26, hour: 17, min: 10, month: 9, sec: 20, year: 2014, frac_sec: 0.321} }
iex>from_erl({{2014, 99, 99}, {17, 10, 20}})
{:error, :invalid_datetime}
Like from_erl/1 without "!", but returns the result directly without a tag. Will raise if date is invalid. Only use this if you are sure the date is valid.
Examples
iex> from_erl!({{2014, 9, 26}, {17, 10, 20}})
%Kalends.NaiveDateTime{day: 26, hour: 17, min: 10, month: 9, sec: 20, year: 2014}
iex from_erl!({{2014, 99, 99}, {17, 10, 20}})
# this will throw a MatchError
Like DateTime.Format.strftime! but for NaiveDateTime.
Refer to documentation for DateTime.Format.strftime!
iex> from_erl!({{2014,10,15},{2,37,22}}) |> strftime! "%Y %h %d"
"2014 Oct 15"
Takes a NaiveDateTime struct and returns a Date struct representing the date part of the provided NaiveDateTime.
iex> from_erl!({{2014,10,15},{2,37,22}}) |> Kalends.NaiveDateTime.to_date
%Kalends.Date{day: 15, month: 10, year: 2014}
For turning NaiveDateTime structs to into a DateTime.
Takes a NaiveDateTime and a timezone name. If timezone is valid, returns a tuple with an :ok and DateTime.
iex> from_erl!({{2014,10,15},{2,37,22}}) |> Kalends.NaiveDateTime.to_date_time("UTC")
{:ok, %Kalends.DateTime{abbr: "UTC", day: 15, frac_sec: nil, hour: 2, min: 37, month: 10, sec: 22, std_off: 0, timezone: "UTC", utc_off: 0, year: 2014}}
Promote to DateTime with UTC time zone.
Takes a NaiveDateTime. Returns a DateTime.
iex> from_erl!({{2014,10,15},{2,37,22}}) |> Kalends.NaiveDateTime.to_date_time_utc
%Kalends.DateTime{abbr: "UTC", day: 15, frac_sec: nil, hour: 2, min: 37, month: 10, sec: 22, std_off: 0, timezone: "UTC", utc_off: 0, year: 2014}
Takes a NaiveDateTime struct and returns an erlang style datetime tuple.
Examples
iex> from_erl!({{2014, 10, 15}, {2, 37, 22}}) |> to_erl
{{2014, 10, 15}, {2, 37, 22}}