compare(_:)
Compares the receiver with the specified date interval.
Declaration
func compare(_ dateInterval: DateInterval) -> ComparisonResultParameters
- dateInterval:
The date interval with which to compare the receiver.
Return Value
Returns an ComparisonResult value that indicates the temporal ordering of the receiver and a given date interval:
ComparisonResult.orderedAscending if the receiver’s startDate occurs earlier than that of
dateInterval, or both startDate values are equal and the duration of the receiver is less than that ofdateInterval.ComparisonResult.orderedDescending if the receiver’s startDate occurs later than that of
dateInterval, or both startDate values are equal and the duration of the receiver is greater than that ofdateInterval.ComparisonResult.orderedSame if the receiver’s startDate and duration values are equal to those of
dateInterval.
Discussion
The following figure illustrates four NSDateInterval objects plotted on an arbitrary time axis. Each date interval spans its duration from left to right, from its startDate to its endDate.
[Image]
The result of comparing the date interval labeled A with the date interval labeled B is ComparisonResult.orderedAscending, because A has a startDate that occurs earlier than that of B.
The result of comparing the date interval labeled C with the date interval labeled D is ComparisonResult.orderedDescending, because because C and D have the same startDate, and C has a duration greater than that of D.