components(_:from:to:options:)
Returns the difference between start and end dates given as date components.
Declaration
func components(_ unitFlags: NSCalendar.Unit, from startingDateComp: DateComponents, to resultDateComp: DateComponents, options: NSCalendar.Options = []) -> DateComponentsParameters
- unitFlags:
Specifies the components for the returned
NSDateComponentsobject. - startingDateComp:
The start date for the calculation as an
NSDateComponentsobject. - resultDateComp:
The end date for the calculation as an
NSDateComponentsobject. - options:
The
optionsparameter is currently unused.
Return Value
An NSDateComponents object whose components are specified by unitFlags and calculated from the difference between the startingDateComp and resultDateComp using the options specified by options. Returns nil if either date falls outside the defined range of the receiver or if the computation cannot be performed.
Discussion
If an NSDateComponents object does not specify a value for a calendar unit required to determine an absolute date, the base value of that unit is assumed. For example, given an NSDateComponents object with only a year and a month specified, the resulting NSDate object would be constructed using a day value of 1 and hour, minute, second and nanosecond values of 0. Passing an NSDateComponents argument with an unspecified era or year value is not advised.
If an NSDateComponents object’s timeZone property is set, the time zone property value will be used in the calculation. If an NSDateComponents object’s calendar property is set, the calendar property value will be used instead of the receiving calendar. If both an NSDateComponents object’s timeZone and calendar properties are set, the time zone property value overrides the time zone of the calendar property value.