From 693ada80e44cc7ab716334041290f9667d60dd19 Mon Sep 17 00:00:00 2001 From: Hristo Staykov Date: Fri, 30 Aug 2024 16:42:08 -0700 Subject: [PATCH 1/3] [Proposal] SF-NNNN Extending Calendar.RecurrenceRule.End This proposal concerns adding couple properties to `Caledar.RecurrenceRule.End`, first introduced in SF-0009. --- ...ndar-recurrence-rule-end-count-and-date.md | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md diff --git a/Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md b/Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md new file mode 100644 index 000000000..8fa067d81 --- /dev/null +++ b/Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md @@ -0,0 +1,58 @@ +# Extending `Calendar.RecurrenceRule.End` + + +* Proposal: SF-NNNN +* Author(s): Hristo Staykov +* Review Manager: [Tina Liu](https://github.com/itingliu) +* Status: **Active review** +* Bugs: +* Implementation: [apple/swift-foundation#888](https://github.com/apple/swift-foundation/pull/888) +* Previous Proposal: [SF-0009](0009-calendar-recurrence-rule.md) + +## Revision history + +* **v1** Initial version + +## Introduction + +In [SF-0009](0009-calendar-recurrence-rule.md) we introduced Calendar.RecurrenceRule API. In this API, we represent the end of a recurrence rule with the struct `Calendar.RecurrenceRule.End`: + +```swift +/// When a recurring event stops recurring +public struct End: Sendable, Equatable { + /// The event stops repeating after a given number of times + /// - Parameter count: how many times to repeat the event, including + /// the first occurrence. `count` must be greater + /// than `0` + public static func afterOccurrences(_ count: Int) -> Self + /// The event stops repeating after a given date + /// - Parameter date: the date on which the event may last occur. No + /// further occurrences will be found after that + public static func afterDate(_ date: Date) -> Self + /// The event repeats indefinitely + public static var never: Self + +} +``` + +This is de-facto an enum, but it was declared as struct to be future-proof. However, the original API only allowed construction of the recurrence rule end, but does not allow any introspection afterwards. This proposal adds a few properties to `Calendar.RecurrenceRule.End` to remedy this. + +## Detailed design + +```swift +public extension Calendar.RecurrenceRule.End { + /// At most many times the event may occur + /// This value is set when the struct was initialized with `.afterOccurrences()` + @available(FoundationPreview 6.0.2, *) + public var count: Int? { get } + + /// The latest date when the event may occur + /// This value is set when the struct was initialized with `.afterDate()` + @available(FoundationPreview 6.0.2, *) + public var date: Date? { get } +} +``` + +## Impact on existing code + +None. From 046fa6f307fbd132a836b6e53ab2cf64c7cf5283 Mon Sep 17 00:00:00 2001 From: Hristo Staykov Date: Tue, 3 Sep 2024 14:06:37 -0700 Subject: [PATCH 2/3] Add CustomStringConvertible conformance --- ...-calendar-recurrence-rule-end-count-and-date.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md b/Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md index 8fa067d81..c3cc8d74a 100644 --- a/Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md +++ b/Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md @@ -12,6 +12,7 @@ ## Revision history * **v1** Initial version +* **v2** Added `CustomStringConvertible` conformance to `Calendar.RecurrenceRule.End`. ## Introduction @@ -37,6 +38,8 @@ public struct End: Sendable, Equatable { This is de-facto an enum, but it was declared as struct to be future-proof. However, the original API only allowed construction of the recurrence rule end, but does not allow any introspection afterwards. This proposal adds a few properties to `Calendar.RecurrenceRule.End` to remedy this. +Additionally, we add `CustomStringConvertible` conformance to the struct. Previously, implementation details would be leaked when printing (`End(_guts: Foundation.Calendar.RecurrenceRule.End.(unknown context at $1a0a00afc)._End.never)`). + ## Detailed design ```swift @@ -51,6 +54,17 @@ public extension Calendar.RecurrenceRule.End { @available(FoundationPreview 6.0.2, *) public var date: Date? { get } } + +@available(FoundationPreview 6.0.2, *) +public extension Calendar.RecurrenceRule.End: CustomStringConvertible { + public var description: String { + switch self._guts { + case .never: "Never" + case .afterDate(let date): "After \(date)" + case .afterOccurrences(let n): "After \(n) occurrences" + } + } +} ``` ## Impact on existing code From ecb16935130a43e65cb93dd001fef4f5a1c7063d Mon Sep 17 00:00:00 2001 From: Hristo Staykov Date: Fri, 6 Sep 2024 15:44:15 -0700 Subject: [PATCH 3/3] Rename `count` to `occurrences` --- Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md b/Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md index c3cc8d74a..df8ebfc97 100644 --- a/Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md +++ b/Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md @@ -13,6 +13,7 @@ * **v1** Initial version * **v2** Added `CustomStringConvertible` conformance to `Calendar.RecurrenceRule.End`. +* **v3** Renamed `count` to `occurrences` ## Introduction @@ -47,7 +48,7 @@ public extension Calendar.RecurrenceRule.End { /// At most many times the event may occur /// This value is set when the struct was initialized with `.afterOccurrences()` @available(FoundationPreview 6.0.2, *) - public var count: Int? { get } + public var occurrences: Int? { get } /// The latest date when the event may occur /// This value is set when the struct was initialized with `.afterDate()`