Instance Method

date(_:matchesComponents:)

Returns whether a given date matches all of the given date components.

Declaration

func date(_ date: Date, matchesComponents components: DateComponents) -> Bool

Parameters

date

The date for which to perform the calculation.

comps

The date components to match.

Return Value

true if the given date matches the given components, otherwise false.

Discussion

This method is useful for determining whether dates calculated by methods like nextDate(after:matching:value:options:) or enumerateDates(startingAfter:matching:options:using:) are exact, or required an adjustment due to a nonexistent time.

See Also

Extracting Components

func component(NSCalendar.Unit, from: Date)

Returns the specified date component from a given date.

func components(NSCalendar.Unit, from: Date)

Returns the date components representing a given date.

func components(NSCalendar.Unit, from: Date, to: Date, options: NSCalendar.Options = [])

Returns the difference between two supplied dates as date components.

func components(NSCalendar.Unit, from: DateComponents, to: DateComponents, options: NSCalendar.Options = [])

Returns the difference between start and end dates given as date components.

func components(in: TimeZone, from: Date)

Returns all the date components of a date, as if in a given time zone (instead of the receiving calendar’s time zone).