Skip to content

Commit e2609e1

Browse files
authored
Update method arguments in SF-0001 to match implementation (swiftlang#362)
1 parent 4bc61cf commit e2609e1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Proposals/0001-calendar-improvements.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ The new `Sequence`-based API is a great fit for Swift because it composes with a
118118
let cal = Calendar(identifier: .gregorian)
119119
let date = Date(timeIntervalSinceReferenceDate: 682869758.712307) // August 22, 2022 at 7:02:38 AM PDT
120120
let dates = zip(
121-
cal.dates(startingAt: date, matching: DateComponents(minute: 0), matchingPolicy: .nextTime),
121+
cal.dates(byMatching: DateComponents(minute: 0), startingAt: date, matchingPolicy: .nextTime)
122122
["1st period", "2nd period", "3rd period"]
123123
)
124124

@@ -134,7 +134,7 @@ Another example is using the generic `prefix` function. Here, it is combined wit
134134
var matchingComps = DateComponents()
135135
matchingComps.dayOfYear = 234
136136
// Including a leap year, find the next 5 "day 234"s
137-
let result = cal.dates(startingAt: date, matching: matchingComps).prefix(5)
137+
let result = cal.dates(byMatching: matchingComps, startingAt: date).prefix(5)
138138
/*
139139
Result:
140140
2022-08-22 00:00:00 +0000
@@ -159,7 +159,7 @@ cal.timeZone = TimeZone.gmt
159159
var dc = DateComponents()
160160
dc.hour = 22
161161

162-
let result = cal.dates(startingAt: startDate, in: startDate..<endDate, matching: dc)
162+
let result = cal.dates(byMatching: dc, startingAt: startDate, in: startDate..<endDate)
163163
/*
164164
Result:
165165
2022-08-23 22:00:00 +0000
@@ -171,7 +171,7 @@ let result = cal.dates(startingAt: startDate, in: startDate..<endDate, matching:
171171
The API also allows for backwards searches. Note that the `Range` remains ordered forward in time as Swift does not allow for reverse ranges. The separation of the starting point from the range allows for the caller to control where they want the search to start in the range (start or end, for example). The search can also start outside of the range, and will return results as long as the first result is inside of the range. The sequence terminates as soon as a result is not contained in the range.
172172

173173
```swift
174-
let result = cal.dates(startingAt: endDate, in: startDate..<endDate, matching: dc, direction: .backward)
174+
let result = cal.dates(byMatching: dc, startingAt: endDate, in: startDate..<endDate, direction: .backward)
175175
/*
176176
Result:
177177
2022-08-25 22:00:00 +0000
@@ -202,7 +202,7 @@ let endDate = startDate + (86400 * 3) + (3600 * 2) // 3 days + 2 hours later - c
202202
var cal = Calendar(identifier: .gregorian)
203203
cal.timeZone = TimeZone(name: "America/Los_Angeles")!
204204

205-
let result = cal.dates(startingAt: startDate, in: startDate..<endDate, byAdding: .day)
205+
let result = cal.dates(byAdding: .day, startingAt: startDate, in: startDate..<endDate)
206206
/*
207207
Result:
208208
2022-11-05 22:02:38 +0000
@@ -218,9 +218,10 @@ The new `dayOfYear` option composes with existing `Calendar` API, and can be use
218218
```swift
219219
let date = Date(timeIntervalSinceReferenceDate: 682898558.712307) // 2022-08-22 22:02:38 UTC, day 234
220220
let dayOfYear = cal.component(.dayOfYear, from: date) // 234
221+
let leapYearDate = cal.date(from: .init(year: 2024, month: 1, day: 1))!
221222

222223
let range1 = cal.range(of: .dayOfYear, in: .year, for: date) // 1..<366
223-
let range2 = cal.range(of: .dayOfYear, in: .year, for: leapYearDate // 1..<367
224+
let range2 = cal.range(of: .dayOfYear, in: .year, for: leapYearDate) // 1..<367
224225

225226
// What day of the week is the 100th day of the year?
226227
let whatDay = cal.date(bySetting: .dayOfYear, value: 100, of: Date.now)!

0 commit comments

Comments
 (0)