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.

Comparing Date Intervals

static func !=(DateInterval, DateInterval)

Returns a Boolean value indicating whether two values are not equal.

static func <(DateInterval, DateInterval)

Indicates whether one date interval is strictly less than another.

static func <=(DateInterval, DateInterval)

Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.

static func ==(DateInterval, DateInterval)

Indicates whether two date intervals are the same.

static func >(DateInterval, DateInterval)

Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.

static func >=(DateInterval, DateInterval)

Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.

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.

Operator Functions

static func ...(DateInterval)

Returns a partial range extending upward from a lower bound.

static func ...(DateInterval)

Returns a partial range up to, and including, its upper bound.

static func ..<(DateInterval)

Returns a partial range up to, but not including, its upper bound.

See Also

Date Representations

struct Date

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

typealias TimeInterval

A number of seconds.