StructureFoundation5.9.0
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.
struct Calendar
Citizens in Foundation
Conformances
protocol CustomDebugStringConvertible
A type with a customized textual representation suitable for debugging purposes.
protocol CustomReflectable
A type that explicitly supplies its own mirror.
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Decodable
A type that can decode itself from an external representation.
protocol Encodable
A type that can encode itself to an external representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol ReferenceConvertible
Decorates types which are backed by a Foundation reference type.
Members
init(from: Decoder
) throws init(identifier: Calendar.Identifier
) Returns a new Calendar.
static var autoupdatingCurrent: Calendar
A Calendar that tracks changes to user’s preferred calendar.
static var current: Calendar
Returns the user’s current calendar.
var amSymbol: String
The symbol used to represent “AM”, localized to the Calendar’s
locale
.var customMirror: Mirror
var debugDescription: String
var description: String
var eraSymbols: [String]
A list of eras in this calendar, localized to the Calendar’s
locale
.var firstWeekday: Int
The first weekday of the calendar.
var identifier: Calendar.Identifier
The identifier of the calendar.
var locale: Locale?
The locale of the calendar.
var longEraSymbols: [String]
A list of longer-named eras in this calendar, localized to the Calendar’s
locale
.var minimumDaysInFirstWeek: Int
The number of minimum days in the first week.
var monthSymbols: [String]
A list of months in this calendar, localized to the Calendar’s
locale
.var pmSymbol: String
The symbol used to represent “PM”, localized to the Calendar’s
locale
.var quarterSymbols: [String]
A list of quarter names in this calendar, localized to the Calendar’s
locale
.var shortMonthSymbols: [String]
A list of shorter-named months in this calendar, localized to the Calendar’s
locale
.var shortQuarterSymbols: [String]
A list of shorter-named quarters in this calendar, localized to the Calendar’s
locale
.var shortStandaloneMonthSymbols: [String]
A list of shorter-named standalone months in this calendar, localized to the Calendar’s
locale
.var shortStandaloneQuarterSymbols: [String]
A list of shorter-named standalone quarters in this calendar, localized to the Calendar’s
locale
.var shortStandaloneWeekdaySymbols: [String]
A list of shorter-named standalone weekdays in this calendar, localized to the Calendar’s
locale
.var shortWeekdaySymbols: [String]
A list of shorter-named weekdays in this calendar, localized to the Calendar’s
locale
.var standaloneMonthSymbols: [String]
A list of standalone months in this calendar, localized to the Calendar’s
locale
.var standaloneQuarterSymbols: [String]
A list of standalone quarter names in this calendar, localized to the Calendar’s
locale
.var standaloneWeekdaySymbols: [String]
A list of standalone weekday names in this calendar, localized to the Calendar’s
locale
.var timeZone: TimeZone
The time zone of the calendar.
var veryShortMonthSymbols: [String]
A list of very-shortly-named months in this calendar, localized to the Calendar’s
locale
.var veryShortStandaloneMonthSymbols: [String]
A list of very-shortly-named standalone months in this calendar, localized to the Calendar’s
locale
.var veryShortStandaloneWeekdaySymbols: [String]
A list of very-shortly-named weekdays in this calendar, localized to the Calendar’s
locale
.var veryShortWeekdaySymbols: [String]
A list of very-shortly-named weekdays in this calendar, localized to the Calendar’s
locale
.var weekdaySymbols: [String]
A list of weekdays in this calendar, localized to the Calendar’s
locale
.static func == (Calendar, Calendar
) -> Bool func compare(Date, to: Date, toGranularity: 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 eitherorderedAscending
ororderedDescending
.func component(Calendar
.Component, from: Date) -> Int Returns the value for one component of a date.
func date(Date, matchesComponents: DateComponents
) -> Bool Determine if the
Date
has all of the specifiedDateComponents
.func date(byAdding: DateComponents, to: Date, wrappingComponents: Bool
) -> Date? Returns a new
Date
representing the date calculated by adding components to a given date.func date(byAdding: Calendar.Component, value: Int, to: Date, wrappingComponents: Bool
) -> Date? Returns a new
Date
representing the date calculated by adding an amount of a specific component to a given date.func date(bySetting: Calendar.Component, value: Int, of: 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: Int, minute: Int, second: Int, of: Date, matchingPolicy: Calendar.MatchingPolicy, repeatedTimePolicy: Calendar.RepeatedTimePolicy, direction: Calendar.SearchDirection
) -> Date? Returns a new
Date
representing the date calculated by setting hour, minute, and second to a given time on a specifiedDate
.func date(from: DateComponents
) -> Date? Returns a date created from the specified components.
func dateComponents(Set
<Calendar.Component>, from: Date) -> DateComponents Returns all the date components of a date, using the calendar time zone.
func dateComponents(Set
<Calendar.Component>, from: DateComponents, to: DateComponents) -> DateComponents Returns the difference between two dates specified as
DateComponents
.func dateComponents(Set
<Calendar.Component>, from: Date, to: Date) -> DateComponents Returns the difference between two dates.
func dateComponents(in: TimeZone, from: 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: Calendar.Component, for: Date
) -> DateInterval? Returns the starting time and duration of a given calendar component that contains a given date.
func dateInterval(of: Calendar.Component, start: inout Date, interval: inout TimeInterval, for: 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
) -> 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, start: inout Date, interval: inout TimeInterval
) -> Bool Find the range of the weekend around the given date, returned via two by-reference parameters.
func encode(to: Encoder
) throws func enumerateDates(startingAfter: Date, matching: DateComponents, matchingPolicy: Calendar.MatchingPolicy, repeatedTimePolicy: Calendar.RepeatedTimePolicy, direction: Calendar.SearchDirection, using: (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: inout Hasher
) func isDate(Date, equalTo: Date, toGranularity: 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(Date, inSameDayAs: 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
) -> Bool Returns
true
if the given date is within today, as defined by the calendar and calendar’s locale.func isDateInTomorrow(Date
) -> Bool Returns
true
if the given date is within tomorrow, as defined by the calendar and calendar’s locale.func isDateInWeekend(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
) -> Bool Returns
true
if the given date is within yesterday, as defined by the calendar and calendar’s locale.func maximumRange(of: Calendar.Component
) -> Range<Int>? The maximum range limits of the values that a given component can take on in the receive
func minimumRange(of: 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, matching: DateComponents, matchingPolicy: Calendar.MatchingPolicy, repeatedTimePolicy: Calendar.RepeatedTimePolicy, direction: Calendar.SearchDirection
) -> Date? Computes the next date which matches (or most closely matches) a given set of components.
func nextWeekend(startingAfter: Date, direction: Calendar.SearchDirection
) -> DateInterval? Returns a
DateInterval
of the next weekend, which starts strictly after the given date.func nextWeekend(startingAfter: Date, start: inout Date, interval: inout TimeInterval, direction: Calendar.SearchDirection
) -> Bool Returns the range of the next weekend via two inout parameters. The weekend starts strictly after the given date.
func ordinality(of: Calendar.Component, in: Calendar.Component, for: 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: Calendar.Component, in: Calendar.Component, for: 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 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.
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.
typealias ReferenceType