RecurrenceRule
A rule which specifies how often an event should repeat in the future
- iOS
- 16.4+
- macOS
- 13.3+
- tvOS
- 16.4+
- watchOS
- 9.4+
struct RecurrenceRule
A rule which specifies how often an event should repeat in the future
struct RecurrenceRule
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.
struct ComponentSet
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.
protocol Copyable
A type whose values can be implicitly or explicitly copied.
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 Escapable
protocol Sendable
init(calendar: Calendar, frequency: Calendar.RecurrenceRule.Frequency, interval: Int = 1, end: Calendar.RecurrenceRule.End = .never, matchingPolicy: Calendar.MatchingPolicy = .nextTimePreservingSmallerComponents, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, months: [Calendar.RecurrenceRule.Month] = [], daysOfTheYear: [Int] = [], daysOfTheMonth: [Int] = [], weeks: [Int] = [], weekdays: [Calendar.RecurrenceRule.Weekday] = [], hours: [Int] = [], minutes: [Int] = [], seconds: [Int] = [], setPositions: [Int] = [])
init(from decoder: any Decoder) throws
static func daily(calendar: Calendar, interval: Int = 1, end: Calendar.RecurrenceRule.End = .never, matchingPolicy: Calendar.MatchingPolicy = .nextTimePreservingSmallerComponents, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, months: [Calendar.RecurrenceRule.Month] = [], daysOfTheMonth: [Int] = [], weekdays: [Calendar.RecurrenceRule.Weekday] = [], hours: [Int] = [], minutes: [Int] = [], seconds: [Int] = [], setPositions: [Int] = []) -> Calendar.RecurrenceRule
A recurrence that repeats every interval
days
static func hourly(calendar: Calendar, interval: Int = 1, end: Calendar.RecurrenceRule.End = .never, matchingPolicy: Calendar.MatchingPolicy = .nextTimePreservingSmallerComponents, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, months: [Calendar.RecurrenceRule.Month] = [], daysOfTheYear: [Int] = [], daysOfTheMonth: [Int] = [], weekdays: [Calendar.RecurrenceRule.Weekday] = [], hours: [Int] = [], minutes: [Int] = [], seconds: [Int] = [], setPositions: [Int] = []) -> Calendar.RecurrenceRule
A recurrence that repeats every interval
hours
static func minutely(calendar: Calendar, interval: Int = 1, end: Calendar.RecurrenceRule.End = .never, matchingPolicy: Calendar.MatchingPolicy = .nextTimePreservingSmallerComponents, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, months: [Calendar.RecurrenceRule.Month] = [], daysOfTheYear: [Int] = [], daysOfTheMonth: [Int] = [], weekdays: [Calendar.RecurrenceRule.Weekday] = [], hours: [Int] = [], minutes: [Int] = [], seconds: [Int] = [], setPositions: [Int] = []) -> Calendar.RecurrenceRule
A recurrence that repeats every interval
minutes
static func monthly(calendar: Calendar, interval: Int = 1, end: Calendar.RecurrenceRule.End = .never, matchingPolicy: Calendar.MatchingPolicy = .nextTimePreservingSmallerComponents, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, months: [Calendar.RecurrenceRule.Month] = [], daysOfTheMonth: [Int] = [], weekdays: [Calendar.RecurrenceRule.Weekday] = [], hours: [Int] = [], minutes: [Int] = [], seconds: [Int] = [], setPositions: [Int] = []) -> Calendar.RecurrenceRule
A recurrence that repeats every interval
months
static func weekly(calendar: Calendar, interval: Int = 1, end: Calendar.RecurrenceRule.End = .never, matchingPolicy: Calendar.MatchingPolicy = .nextTimePreservingSmallerComponents, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, months: [Calendar.RecurrenceRule.Month] = [], weekdays: [Calendar.RecurrenceRule.Weekday] = [], hours: [Int] = [], minutes: [Int] = [], seconds: [Int] = [], setPositions: [Int] = []) -> Calendar.RecurrenceRule
A recurrence that repeats every interval
weeks
static func yearly(calendar: Calendar, interval: Int = 1, end: Calendar.RecurrenceRule.End = .never, matchingPolicy: Calendar.MatchingPolicy = .nextTimePreservingSmallerComponents, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, months: [Calendar.RecurrenceRule.Month] = [], daysOfTheYear: [Int] = [], daysOfTheMonth: [Int] = [], weeks: [Int] = [], weekdays: [Calendar.RecurrenceRule.Weekday] = [], hours: [Int] = [], minutes: [Int] = [], seconds: [Int] = [], setPositions: [Int] = []) -> Calendar.RecurrenceRule
A recurrence that repeats every interval
years
var calendar: Calendar
The calendar in which the recurrence occurs
var daysOfTheMonth: [Int]
On which days in the month the event should occur
var daysOfTheYear: [Int]
On which days of the year the event may occur.
var end: Calendar.RecurrenceRule.End
For how long the event repeats
var frequency: Calendar.RecurrenceRule.Frequency
How often the event repeats
var hours: [Int]
On which hours of a 24-hour day the event should repeat.
var interval: Int
At what interval to repeat
var matchingPolicy: Calendar.MatchingPolicy
What to do when a recurrence is not a valid date
var minutes: [Int]
On which minutes of the hour the event should repeat. Accepts values between 0 and 59
var months: [Calendar.RecurrenceRule.Month]
On which months the event should occur.
var repeatedTimePolicy: Calendar.RepeatedTimePolicy
What to do when there are multiple recurrences occurring at the same time of the day but in different time zones due to a daylight saving transition.
var seconds: [Int]
On which seconds of the minute the event should repeat. Valid values between 0 and 60
var setPositions: [Int]
Which occurrences within every interval should be returned
var weekdays: [Calendar.RecurrenceRule.Weekday]
On which days of the week the event should occur
var weeks: [Int]
On which weeks of the year the event should occur.
func encode(to encoder: any Encoder) throws
func recurrences(of start: Date, in range: Range<Date>? = nil) -> some Sendable & Sequence<Date>
Find recurrences of the given date
struct End
When a recurring event stops recurring
enum Frequency
How often a recurring event repeats
struct Month
Uniquely identifies a month in any calendar system
enum Weekday
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.