Cldr.Calendar.Duration.new-exclamation-mark

You're seeing just the function new-exclamation-mark, go back to Cldr.Calendar.Duration module for more information.

Specs

new!(interval()) :: t() | no_return()

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 either Date.Range.t() or a CalendarInterval.t()

Returns

  • A duration struct or

  • raises an exception

Notes

Example

iex> Cldr.Calendar.Duration.new!(Date.range(~D[2019-01-01], ~D[2019-12-31]))
%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()) ::
  t() | no_return()

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

Note that from must be before or at the same time as to. In addition, both from and to must be in the same calendar.

Returns

  • A duration struct or

  • raises an exception

Example

iex> Cldr.Calendar.Duration.new!(~D[2019-01-01], ~D[2019-12-31])
%Cldr.Calendar.Duration{
  year: 0,
  month: 11,
  day: 30,
  hour: 0,
  microsecond: 0,
  minute: 0,
  second: 0
}