Structure
DateInterval
iOS 10.0+
iPadOS 10.0+
Mac Catalyst 10.0+
macOS 10.12+
tvOS 10.0+
watchOS 3.0+
The span of time between a specific start date and end date.
struct DateInterval
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
Operators
static func == (DateInterval, DateInterval) -> Boolstatic func < (DateInterval, DateInterval) -> Bool
Initializers
init()Initializes an interval with start and end dates set to the current date and the duration set to0.init(from: any Decoder) throwsinit(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.
Instance Properties
var duration: TimeIntervalThe duration.var end: DateThe end date.var start: DateThe start date.
Instance Methods
func compare(DateInterval) -> ComparisonResultCompares two intervals.func contains(Date) -> BoolIndicates whether this interval contains the given date.func hash(into: inout Hasher)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) -> BoolIndicates whether this interval intersects the specified interval.
Default Implementations
Relationships
Conforms To
Swift.ComparableSwift.CopyableSwift.CustomDebugStringConvertibleSwift.CustomReflectableSwift.CustomStringConvertibleSwift.DecodableSwift.EncodableSwift.EquatableSwift.EscapableSwift.HashableSwift.SendableSwift.SendableMetatype