Skip to content

[Proposal] SF-NNNN Extending Calendar.RecurrenceRule.End #889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Proposals/NNNN-calendar-recurrence-rule-end-count-and-date.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Extending `Calendar.RecurrenceRule.End`

* Proposal: SF-NNNN
* Author(s): Hristo Staykov <[email protected]>
* Review Manager: [Tina Liu](https://github.com/itingliu)
* Status: **Active review**
* Bugs: <rdar://134294130>
* 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`. 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 that was declared as struct to be future-proof. However, the original API only allowed construction of the recurrence rule end, and did 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.