Structure

DateInterval

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

Declaration

struct DateInterval, Codable

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) -> Bool

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

static func < (DateInterval, DateInterval) -> Bool

Indicates whether one date interval is strictly less than another.

static func <= (DateInterval, DateInterval) -> Bool

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) -> Bool

Indicates whether two date intervals are the same.

static func > (DateInterval, DateInterval) -> Bool

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

static func >= (DateInterval, DateInterval) -> Bool

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) -> DateInterval?

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

func intersects(DateInterval) -> Bool

Indicates whether this interval intersects the specified interval.

Determining Whether a Date Occurs Within a Date Interval

func contains(Date) -> Bool

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.

Operator Functions

static func ... (DateInterval) -> PartialRangeFrom<DateInterval>

Returns a partial range extending upward from a lower bound.

static func ... (DateInterval) -> PartialRangeThrough<DateInterval>

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

static func ... (DateInterval, DateInterval) -> ClosedRange<DateInterval>

Returns a closed range that contains both of its bounds.

static func ..< (DateInterval) -> PartialRangeUpTo<DateInterval>

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

static func ..< (DateInterval, DateInterval) -> Range<DateInterval>

Returns a half-open range that contains its lower bound but not 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.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software