Structure

DateInterval

The span of time between a specific start date and end date.

Overview

DateInterval represents a closed date interval in the form of [startDate, endDate]. It is possible for the start and end dates to be the same with a duration of 0. DateInterval does not support reverse intervals i.e. intervals where the duration is less than 0 and the end date occurs earlier in time than the start date.

Topics

Creating a Date Interval

init()

Initializes an interval with start and end dates set to the current date and the duration set to 0.

init(start: Date, duration: TimeInterval)

Initializes an interval with the specified start date and duration.

init(start: Date, end: Date)

Initializes an interval with the specified start and end date.

Accessing Start Date, End Date, and Duration

var start: Date

The start date.

var end: Date

The end date.

Determining Intersections

func intersection(with: DateInterval)

Returns an interval that represents the interval where the given date interval and the current instance intersect.

func intersects(DateInterval)

Indicates whether this interval intersects the specified interval.

Determining Whether a Date Occurs Within a Date Interval

func contains(Date)

Indicates whether this interval contains the given date.

Describing a Date Interval

var description: String

A textual description of the date interval.

var debugDescription: String

A textual description of the date interval suitable for debugging.

var customMirror: Mirror

A mirror that reflects the date interval.

var hashValue: Int

The computed hash value for the date interval.

Using Reference Types

class NSDateInterval

An object representing the span of time between two dates that bridges to DateInterval; use NSDateInterval when you need reference semantics or other Foundation-specific behavior.

typealias DateInterval.ReferenceType

An alias for this value type's equivalent reference type.

Instance Methods

func compare(DateInterval)

Compares two intervals.

See Also

Date Representations

struct Date

A specific point in time, independent of any calendar or time zone.

typealias TimeInterval

A number of seconds.