Cldr.Calendar.Duration.new
new
, go back to Cldr.Calendar.Duration module for more information.
Specs
Calculates the calendar difference in
a Date.Range
or CalendarInterval
returning a Duration
struct.
The difference calculated is in terms of years, months, days, hours, minutes, seconds and microseconds.
Arguments
interval
is eitherDate.Range.t()
or aCalendarInterval.t()
Returns
A
{:ok, duration}
tuple or a{:error, {exception, reason}}
tuple
Notes
CalendarInterval
is defined by the most wonderful calendar_interval library.
Example
iex> Cldr.Calendar.Duration.new(Date.range(~D[2019-01-01], ~D[2019-12-31]))
{:ok,
%Cldr.Calendar.Duration{
year: 0,
month: 11,
day: 30,
hour: 0,
microsecond: 0,
minute: 0,
second: 0
}}
Specs
new(from :: date_or_time_or_datetime(), to :: date_or_time_or_datetime()) :: {:ok, t()} | {:error, {module(), String.t()}}
Calculates the calendar difference between two dates
returning a Duration
struct.
The difference calculated is in terms of years, months, days, hours, minutes, seconds and microseconds.
Arguments
from
is a date, time or datetime representing the start of the duration.to
is a date, time or datetime representing the end of the duration
Notes
from
must be before or at the same time asto
. In addition, bothfrom
andto
must be in the same calendarIf
from
andto
aredatetime
s then they must both be in the same time zone
Returns
A
{:ok, duration}
tuple or a{:error, {exception, reason}}
tuple
Example
iex> Cldr.Calendar.Duration.new(~D[2019-01-01], ~D[2019-12-31])
{:ok,
%Cldr.Calendar.Duration{
year: 0,
month: 11,
day: 30,
hour: 0,
microsecond: 0,
minute: 0,
second: 0
}}