ComponentSet
- iOS
- 8.0+
- macOS
- 10.10+
- tvOS
- 9.0+
- watchOS
- 2.0+
struct ComponentSet
struct ComponentSet
import FoundationEssentials
struct Calendar
Calendar
encapsulates information about systems of reckoning time in which the beginning, length, and divisions of a year are defined. It provides information about the calendar and support for calendrical computations such as determining the range of a given calendrical unit and adding units to a given absolute time.
init(from decoder: any Decoder) throws
init(identifier: Calendar.Identifier)
Returns a new Calendar.
static var autoupdatingCurrent: Calendar { get }
A Calendar that tracks changes to user’s preferred calendar.
static var current: Calendar { get }
Returns the user’s current calendar.
var customMirror: Mirror { get }
var debugDescription: String { get }
var description: String { get }
var firstWeekday: Int { get set }
The first weekday of the calendar.
var identifier: Calendar.Identifier { get }
The identifier of the calendar.
var locale: Locale? { get set }
The locale of the calendar.
var minimumDaysInFirstWeek: Int { get set }
The number of minimum days in the first week.
var timeZone: TimeZone { get set }
The time zone of the calendar.
static func == (lhs: Calendar, rhs: Calendar) -> Bool
func compare(_ date1: Date, to date2: Date, toGranularity component: Calendar.Component) -> ComparisonResult
Compares the given dates down to the given component, reporting them orderedSame
if they are the same in the given component and all larger components, otherwise either orderedAscending
or orderedDescending
.
func component(_ component: Calendar.Component, from date: Date) -> Int
Returns the value for one component of a date.
func date(_ date: Date, matchesComponents components: DateComponents) -> Bool
Determine if the Date
has all of the specified DateComponents
.
func date(byAdding components: DateComponents, to date: Date, wrappingComponents: Bool = false) -> Date?
Returns a new Date
representing the date calculated by adding components to a given date.
func date(byAdding component: Calendar.Component, value: Int, to date: Date, wrappingComponents: Bool = false) -> Date?
Returns a new Date
representing the date calculated by adding an amount of a specific component to a given date.
func date(bySetting component: Calendar.Component, value: Int, of date: Date) -> Date?
Returns a new Date
representing the date calculated by setting a specific component to a given time, and trying to keep lower components the same. If the component already has that value, this may result in a date which is the same as the given date.
func date(bySettingHour hour: Int, minute: Int, second: Int, of date: Date, matchingPolicy: Calendar.MatchingPolicy = .nextTime, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, direction: Calendar.SearchDirection = .forward) -> Date?
Returns a new Date
representing the date calculated by setting hour, minute, and second to a given time on a specified Date
.
func date(from components: DateComponents) -> Date?
Returns a date created from the specified components.
func dateComponents(_ components: Set<Calendar.Component>, from date: Date) -> DateComponents
Returns all the date components of a date, using the calendar time zone.
func dateComponents(_ components: Set<Calendar.Component>, from start: DateComponents, to end: DateComponents) -> DateComponents
Returns the difference between two dates specified as DateComponents
.
func dateComponents(_ components: Set<Calendar.Component>, from start: Date, to end: Date) -> DateComponents
Returns the difference between two dates.
func dateComponents(in timeZone: TimeZone, from date: Date) -> DateComponents
Returns all the date components of a date, as if in a given time zone (instead of the Calendar
time zone).
func dateInterval(of component: Calendar.Component, for date: Date) -> DateInterval?
Returns the starting time and duration of a given calendar component that contains a given date.
func dateInterval(of component: Calendar.Component, start: inout Date, interval: inout TimeInterval, for date: Date) -> Bool
Returns, via two inout parameters, the starting time and duration of a given calendar component that contains a given date.
func dateIntervalOfWeekend(containing date: Date) -> DateInterval?
Returns a DateInterval
of the weekend contained by the given date, or nil if the date is not in a weekend.
func dateIntervalOfWeekend(containing date: Date, start: inout Date, interval: inout TimeInterval) -> Bool
Finds the range of the weekend around the given date, and returns the starting date and duration of the weekend via two inout parameters.
func dates(byAdding components: DateComponents, startingAt start: Date, in range: Range<Date>? = nil, wrappingComponents: Bool = false) -> some Sendable & Sequence<Date>
Returns a sequence of Date
s, calculated by repeatedly adding an amount of DateComponents
to a starting Date
and then to each subsequent result. If a range is supplied, the sequence terminates if the next result is not contained in the range. The starting point does not need to be contained in the range, but if the first result is outside of the range then the result will be an empty sequence.
func dates(byAdding component: Calendar.Component, value: Int = 1, startingAt start: Date, in range: Range<Date>? = nil, wrappingComponents: Bool = false) -> some Sendable & Sequence<Date>
Returns a sequence of Date
s, calculated by adding a scaled amount of Calendar.Component
s to a starting Date
. If a range is supplied, the sequence terminates if the next result is not contained in the range. The starting point does not need to be contained in the range, but if the first result is outside of the range then the result will be an empty sequence.
func dates(byMatching components: DateComponents, startingAt start: Date, in range: Range<Date>? = nil, matchingPolicy: Calendar.MatchingPolicy = .nextTime, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, direction: Calendar.SearchDirection = .forward) -> some Sendable & Sequence<Date>
Computes the dates which match (or most closely match) a given set of components, returned as a Sequence
.
func encode(to encoder: any Encoder) throws
func enumerateDates(startingAfter start: Date, matching components: DateComponents, matchingPolicy: Calendar.MatchingPolicy, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, direction: Calendar.SearchDirection = .forward, using block: (Date?, Bool, inout Bool) -> Void)
Computes the dates which match (or most closely match) a given set of components, and calls the closure once for each of them, until the enumeration is stopped.
func hash(into hasher: inout Hasher)
func isDate(_ date1: Date, equalTo date2: Date, toGranularity component: Calendar.Component) -> Bool
Compares the given dates down to the given component, reporting them equal if they are the same in the given component and all larger components.
func isDate(_ date1: Date, inSameDayAs date2: Date) -> Bool
Returns true
if the given date is within the same day as another date, as defined by the calendar and calendar’s locale.
func isDateInToday(_ date: Date) -> Bool
Returns true
if the given date is within today, as defined by the calendar and calendar’s locale.
func isDateInTomorrow(_ date: Date) -> Bool
Returns true
if the given date is within tomorrow, as defined by the calendar and calendar’s locale.
func isDateInWeekend(_ date: Date) -> Bool
Returns true
if the given date is within a weekend period, as defined by the calendar and calendar’s locale.
func isDateInYesterday(_ date: Date) -> Bool
Returns true
if the given date is within yesterday, as defined by the calendar and calendar’s locale.
func maximumRange(of component: Calendar.Component) -> Range<Int>?
The maximum range limits of the values that a given component can take on in the receive
func minimumRange(of component: Calendar.Component) -> Range<Int>?
Returns the minimum range limits of the values that a given component can take on in the receiver.
func nextDate(after date: Date, matching components: DateComponents, matchingPolicy: Calendar.MatchingPolicy, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, direction: Calendar.SearchDirection = .forward) -> Date?
Computes the next date which matches (or most closely matches) a given set of components.
func nextWeekend(startingAfter date: Date, direction: Calendar.SearchDirection = .forward) -> DateInterval?
Returns a DateInterval
of the next weekend, which starts strictly after the given date.
func nextWeekend(startingAfter date: Date, start: inout Date, interval: inout TimeInterval, direction: Calendar.SearchDirection = .forward) -> Bool
Returns the range of the next weekend via two inout parameters. The weekend starts strictly after the given date.
func ordinality(of smaller: Calendar.Component, in larger: Calendar.Component, for date: Date) -> Int?
Returns, for a given absolute time, the ordinal number of a smaller calendar component (such as a day) within a specified larger calendar component (such as a week).
func range(of smaller: Calendar.Component, in larger: Calendar.Component, for date: Date) -> Range<Int>?
Returns the range of absolute time values that a smaller calendar component (such as a day) can take on in a larger calendar component (such as a month) that includes a specified absolute time.
func startOfDay(for date: Date) -> Date
Returns the first moment of a given Date, as a Date.
enum Component
An enumeration for the various components of a calendar date.
enum Identifier
Calendar supports many different kinds of calendars. Each is identified by an identifier here.
enum MatchingPolicy
A hint to the search algorithm to control the method used for searching for dates.
struct RecurrenceRule
A rule which specifies how often an event should repeat in the future
enum RepeatedTimePolicy
Determines which result to use when a time is repeated on a day in a calendar (for example, during a daylight saving transition when the times between 2:00am and 3:00am may happen twice).
enum SearchDirection
The direction in time to search.
protocol Equatable
A type that can be compared for value equality.
protocol ExpressibleByArrayLiteral
A type that can be initialized using an array literal.
protocol OptionSet : RawRepresentable, SetAlgebra
A type that presents a mathematical set interface to a bit set.
protocol RawRepresentable<RawValue>
A type that can be converted to and from an associated raw value.
protocol Sendable
protocol SetAlgebra<Element> : Equatable, ExpressibleByArrayLiteral
A type that provides mathematical set operations.
init(_ components: Set<Calendar.Component>)
init(_ components: Calendar.Component...)
init(rawValue: UInt)
init(single component: Calendar.Component)
static let calendar: Calendar.ComponentSet
static let day: Calendar.ComponentSet
static let dayOfYear: Calendar.ComponentSet
static let era: Calendar.ComponentSet
static let hour: Calendar.ComponentSet
static let isLeapMonth: Calendar.ComponentSet
static let minute: Calendar.ComponentSet
static let month: Calendar.ComponentSet
static let nanosecond: Calendar.ComponentSet
static let quarter: Calendar.ComponentSet
static let second: Calendar.ComponentSet
static let timeZone: Calendar.ComponentSet
static let weekOfMonth: Calendar.ComponentSet
static let weekOfYear: Calendar.ComponentSet
static let weekday: Calendar.ComponentSet
static let weekdayOrdinal: Calendar.ComponentSet
static let year: Calendar.ComponentSet
static let yearForWeekOfYear: Calendar.ComponentSet
var count: Int { get }
var highestSetUnit: Calendar.Component? { get }
let rawValue: UInt
var set: Set<Calendar.Component> { get }
init()
Creates an empty option set.
init<S>(_ sequence: S) where S : Sequence, Self.Element == S.Element
Creates a new set from a finite sequence of items.
init(arrayLiteral: Self.Element...)
Creates a set containing the elements of the given array literal.
var isEmpty: Bool { get }
A Boolean value that indicates whether the set has no elements.
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.
func contains(_ member: Self) -> Bool
Returns a Boolean value that indicates whether a given element is a member of the option set.
mutating func formIntersection(_ other: Self)
Removes all elements of this option set that are not also present in the given set.
mutating func formSymmetricDifference(_ other: Self)
Replaces this set with a new set containing all elements contained in either this set or the given set, but not in both.
mutating func formUnion(_ other: Self)
Inserts the elements of another set into this option set.
@discardableResult mutating func insert(_ newMember: Self.Element) -> (inserted: Bool, memberAfterInsert: Self.Element)
Adds the given element to the option set if it is not already a member.
func intersection(_ other: Self) -> Self
Returns a new option set with only the elements contained in both this set and the given set.
func isDisjoint(with other: Self) -> Bool
Returns a Boolean value that indicates whether the set has no members in common with the given set.
func isStrictSubset(of other: Self) -> Bool
Returns a Boolean value that indicates whether this set is a strict subset of the given set.
func isStrictSuperset(of other: Self) -> Bool
Returns a Boolean value that indicates whether this set is a strict superset of the given set.
func isSubset(of other: Self) -> Bool
Returns a Boolean value that indicates whether the set is a subset of another set.
func isSuperset(of other: Self) -> Bool
Returns a Boolean value that indicates whether the set is a superset of the given set.
@discardableResult mutating func remove(_ member: Self.Element) -> Self.Element?
Removes the given element and all elements subsumed by it.
mutating func subtract(_ other: Self)
Removes the elements of the given set from this set.
func subtracting(_ other: Self) -> Self
Returns a new set containing the elements of this set that do not occur in the given set.
func symmetricDifference(_ other: Self) -> Self
Returns a new option set with the elements contained in this set or in the given set, but not in both.
func union(_ other: Self) -> Self
Returns a new option set of the elements contained in this set, in the given set, or in both.
@discardableResult mutating func update(with newMember: Self.Element) -> Self.Element?
Inserts the given element into the set.