One Logo Pool Ball
Foundation · IOS API REFERENCE

DateInterval

struct · iOS 10.0+ · SDK 27.1

struct DateInterval

The span of time between a specific start date and end date. `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.

Members (16)

method · iOS 10.0+

intersects

TypeScript
intersects(dateInterval: DateInterval): boolean
Swift declaration
func intersects(_ dateInterval: DateInterval) -> Bool

Indicates whether this interval intersects the specified interval.

get · iOS 10.0+

description

TypeScript
get description(): string
Swift declaration
var description: String { get }

A textual representation of this instance. Calling this property directly is discouraged. Instead, convert an instance of any type to a string by using the `String(describing:)` initializer. This initializer works with any type, and uses the custom `description` property for types that conform to `CustomStringConvertible`: struct Point: CustomStringConvertible { let x: Int, y: Int var description: String { return "(\(x), \(y))" } } let p = Point(x: 21, y: 30) let s = String(describing: p) print(s) // Prints "(21, 30)" The conversion of `p` to a string in the assignment to `s` uses the `Point` type's `description` property.

get · iOS 10.0+

customMirror

TypeScript
get customMirror(): SDKHandle
Swift declaration
var customMirror: Mirror { get }

The custom mirror for this instance. If this type has value semantics, the mirror should be unaffected by subsequent mutations of the instance.

method · iOS 10.0+

intersection

TypeScript
intersection(dateInterval: DateInterval): (DateInterval) | null
Swift declaration
func intersection(with dateInterval: DateInterval) -> DateInterval?

Returns an interval that represents the interval where the given date interval and the current instance intersect. In the event that there is no intersection, the method returns `nil`.

get · iOS 10.0+

debugDescription

TypeScript
get debugDescription(): string
Swift declaration
var debugDescription: String { get }

A textual representation of this instance, suitable for debugging. Calling this property directly is discouraged. Instead, convert an instance of any type to a string by using the `String(reflecting:)` initializer. This initializer works with any type, and uses the custom `debugDescription` property for types that conform to `CustomDebugStringConvertible`: struct Point: CustomDebugStringConvertible { let x: Int, y: Int var debugDescription: String { return "(\(x), \(y))" } } let p = Point(x: 21, y: 30) let s = String(reflecting: p) print(s) // Prints "(21, 30)" The conversion of `p` to a string in the assignment to `s` uses the `Point` type's `debugDescription` property.

get · iOS 10.0+

end

TypeScript
get end(): globalThis.Date
Swift declaration
var end: Date { get set }

The end date. - Precondition: `end >= start`

set · iOS 10.0+

end

TypeScript
set end(value: globalThis.Date)
Swift declaration
var end: Date { get set }

The end date. - Precondition: `end >= start`

init · iOS 10.0+

init

TypeScript
static initStartEnd(start: globalThis.Date, end: globalThis.Date): DateInterval
Swift declaration
init(start: Date, end: Date)

Initializes an interval with the specified start and end date. - Precondition: `end >= start`

init · iOS 10.0+

init

TypeScript
static initStartDuration(start: globalThis.Date, duration: number): DateInterval
Swift declaration
init(start: Date, duration: TimeInterval)

Initializes an interval with the specified start date and duration. - Precondition: `duration >= 0`

get · iOS 10.0+

start

TypeScript
get start(): globalThis.Date
Swift declaration
var start: Date

The start date.

set · iOS 10.0+

start

TypeScript
set start(value: globalThis.Date)
Swift declaration
var start: Date

The start date.

method · iOS 10.0+

compare

TypeScript
compare(dateInterval: DateInterval): ComparisonResult
Swift declaration
func compare(_ dateInterval: DateInterval) -> ComparisonResult

Compares two intervals. This method prioritizes ordering by start date. If the start dates are equal, then it will order by duration. e.g. Given intervals a and b ``` a. |-----| b. |-----| ``` `a.compare(b)` would return `.orderedAscending` because a's start date is earlier in time than b's start date. In the event that the start dates are equal, the compare method will attempt to order by duration. e.g. Given intervals c and d ``` c. |-----| d. |---| ``` `c.compare(d)` would result in `.orderedDescending` because c is longer than d. If both the start dates and the durations are equal, then the intervals are considered equal and `.orderedSame` is returned as the result.

method · iOS 10.0+

contains

TypeScript
contains(date: globalThis.Date): boolean
Swift declaration
func contains(_ date: Date) -> Bool

Indicates whether this interval contains the given date.

get · iOS 10.0+

duration

TypeScript
get duration(): number
Swift declaration
var duration: TimeInterval { get set }

The duration. - Precondition: `duration >= 0`

set · iOS 10.0+

duration

TypeScript
set duration(value: number)
Swift declaration
var duration: TimeInterval { get set }

The duration. - Precondition: `duration >= 0`

init · iOS 10.0+

init

TypeScript
static init(): DateInterval
Swift declaration
init()

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

Skipped declarations

No declarations were skipped in this snapshot.

All Foundation types →