/// <summary> /// Gets the last calendar day in the specified calendar-based unit-of-time. /// </summary> /// <param name="unitOfTime">The unit-of-time.</param> /// <returns> /// The last calendar day in the specified calendar-based unit-of-time. /// </returns> /// <exception cref="ArgumentNullException"><paramref name="unitOfTime"/> is null.</exception> /// <exception cref="InvalidOperationException"><paramref name="unitOfTime"/> is unbounded.</exception> public static CalendarDay GetLastCalendarDay( this CalendarUnitOfTime unitOfTime) { if (unitOfTime == null) { throw new ArgumentNullException(nameof(unitOfTime)); } switch (unitOfTime) { case CalendarDay unitOfTimeAsCalendarDay: return(unitOfTimeAsCalendarDay.GetLastCalendarDay()); case CalendarMonth unitOfTimeAsCalendarMonth: return(unitOfTimeAsCalendarMonth.GetLastCalendarDay()); case CalendarQuarter unitOfTimeAsCalendarQuarter: return(unitOfTimeAsCalendarQuarter.GetLastCalendarDay()); case CalendarYear unitOfTimeAsCalendarYear: return(unitOfTimeAsCalendarYear.GetLastCalendarDay()); case CalendarUnbounded _: throw new InvalidOperationException("There is no last day in unbounded time."); } throw new NotSupportedException("this type of unit-of-time is not supported: " + unitOfTime.GetType()); }
/// <inheritdoc /> public override RelativeSortOrder CompareToForRelativeSortOrder(CalendarUnitOfTime other) { if (ReferenceEquals(other, null)) { return(RelativeSortOrder.ThisInstanceFollowsTheOtherInstance); } if (!(other is CalendarMonth otherAsCalendarMonth)) { throw new ArgumentException(Invariant($"Attempting to compare objects of different types. This object is of type 'CalendarMonth' whereas the other object is of type '{other.GetType().ToStringReadable()}'.")); } var result = this.CompareToForRelativeSortOrder(otherAsCalendarMonth); return(result); }