Esempio n. 1
0
 /// <summary>
 /// Returns the exact difference between two dates.
 /// </summary>
 /// <remarks>
 /// If <paramref name="end"/> is before <paramref name="start" />, each property in the returned period
 /// will be negative.
 /// </remarks>
 /// <param name="start">Start date</param>
 /// <param name="end">End date</param>
 /// <returns>The period between the two dates, using year, month and day units.</returns>
 public static Period Between(LocalDate start, LocalDate end)
 {
     return(Between(start.AtMidnight(), end.AtMidnight(), PeriodUnits.YearMonthDay));
 }
Esempio n. 2
0
 /// <summary>
 /// Returns the period between a start and an end date, using only the given units.
 /// </summary>
 /// <remarks>
 /// If <paramref name="end"/> is before <paramref name="start" />, each property in the returned period
 /// will be negative. If the given set of units cannot exactly reach the end point (e.g. finding
 /// the difference between 12th February and 15th March in months) the result will be such that adding it to <paramref name="start"/>
 /// will give a value between <paramref name="start"/> and <paramref name="end"/>. In other words,
 /// any rounding is "towards start"; this is true whether the resulting period is negative or positive.
 /// </remarks>
 /// <param name="start">Start date</param>
 /// <param name="end">End date</param>
 /// <param name="units">Units to use for calculations</param>
 /// <exception cref="ArgumentException"><paramref name="units"/> contains time units, is empty or contains unknown values.</exception>
 /// <exception cref="ArgumentException"><paramref name="start"/> and <paramref name="end"/> use different calendars.</exception>
 /// <returns>The period between the given dates, using the given units.</returns>
 public static Period Between(LocalDate start, LocalDate end, PeriodUnits units)
 {
     Preconditions.CheckArgument((units & PeriodUnits.AllTimeUnits) == 0, "units", "Units contains time units: {0}", units);
     return(Between(start.AtMidnight(), end.AtMidnight(), units));
 }