Skip to content

Commit 2652f8b

Browse files
authored
Merge pull request #1458 from swiftlang/automerge/merge-main-2025-07-31_09-06
Merge `release/6.2` into `main`
2 parents 3c456c5 + a1c611f commit 2652f8b

File tree

2 files changed

+41
-36
lines changed

2 files changed

+41
-36
lines changed

Tests/FoundationEssentialsTests/GregorianCalendarRecurrenceRuleTests.swift

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,6 @@ private struct GregorianCalendarRecurrenceRuleTests {
2626
gregorian.timeZone = .gmt
2727
return gregorian
2828
}()
29-
30-
@Test func roundtripEncoding() throws {
31-
// These are not necessarily valid recurrence rule, they are constructed
32-
// in a way to test all encoding paths
33-
var calendar = Calendar(identifier: .gregorian)
34-
calendar.locale = .init(identifier: "en_001")
35-
calendar.timeZone = try #require(TimeZone(secondsFromGMT: 0))
36-
37-
var recurrenceRule1 = Calendar.RecurrenceRule(calendar: calendar, frequency: .daily)
38-
recurrenceRule1.interval = 2
39-
recurrenceRule1.months = [1, 2, Calendar.RecurrenceRule.Month(4, isLeap: true)]
40-
recurrenceRule1.weeks = [2, 3]
41-
recurrenceRule1.weekdays = [.every(.monday), .nth(1, .wednesday)]
42-
recurrenceRule1.end = .afterOccurrences(5)
43-
44-
var recurrenceRule2 = Calendar.RecurrenceRule(calendar: calendar, frequency: .daily)
45-
recurrenceRule2.months = [2, 10]
46-
recurrenceRule2.weeks = [1, -1]
47-
recurrenceRule2.setPositions = [1]
48-
recurrenceRule2.hours = [14]
49-
recurrenceRule2.minutes = [30]
50-
recurrenceRule2.seconds = [0]
51-
recurrenceRule2.daysOfTheYear = [1]
52-
recurrenceRule2.daysOfTheMonth = [4]
53-
recurrenceRule2.weekdays = [.every(.monday), .nth(1, .wednesday)]
54-
recurrenceRule2.end = .afterDate(.distantFuture)
55-
56-
let recurrenceRule1JSON = try JSONEncoder().encode(recurrenceRule1)
57-
let recurrenceRule2JSON = try JSONEncoder().encode(recurrenceRule2)
58-
let decoded1 = try JSONDecoder().decode(Calendar.RecurrenceRule.self, from: recurrenceRule1JSON)
59-
let decoded2 = try JSONDecoder().decode(Calendar.RecurrenceRule.self, from: recurrenceRule2JSON)
60-
61-
#expect(recurrenceRule1 == decoded1)
62-
#expect(recurrenceRule2 == decoded2)
63-
#expect(recurrenceRule1 != recurrenceRule2)
64-
}
6529

6630
@Test func simpleDailyRecurrence() {
6731
let start = Date(timeIntervalSince1970: 1285027200.0) // 2010-09-21T00:00:00-0000

Tests/FoundationInternationalizationTests/CalendarRecurrenceRuleTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,47 @@ private struct CalendarRecurrenceRuleTests {
2828
return gregorian
2929
}()
3030

31+
@Test func roundtripEncoding() async throws {
32+
// This test does not directly use the current Calendar, however encoding any Calendar will check if it is equivalent to the current Calendar
33+
// If equivalent, it will serialize a sentinel value and deserialize as the current Calendar regardless of the actual serialized identifier
34+
// This test will fail if calendar == Calendar.current at encode time and the current calendar changes to a different value before decode time (making the encoded calendar and the decoded calendar not equivalent
35+
try await usingCurrentInternationalizationPreferences {
36+
// These are not necessarily valid recurrence rule, they are constructed
37+
// in a way to test all encoding paths
38+
var calendar = Calendar(identifier: .gregorian)
39+
calendar.locale = .init(identifier: "en_001")
40+
calendar.timeZone = try #require(TimeZone(secondsFromGMT: 0))
41+
42+
var recurrenceRule1 = Calendar.RecurrenceRule(calendar: calendar, frequency: .daily)
43+
recurrenceRule1.interval = 2
44+
recurrenceRule1.months = [1, 2, Calendar.RecurrenceRule.Month(4, isLeap: true)]
45+
recurrenceRule1.weeks = [2, 3]
46+
recurrenceRule1.weekdays = [.every(.monday), .nth(1, .wednesday)]
47+
recurrenceRule1.end = .afterOccurrences(5)
48+
49+
var recurrenceRule2 = Calendar.RecurrenceRule(calendar: calendar, frequency: .daily)
50+
recurrenceRule2.months = [2, 10]
51+
recurrenceRule2.weeks = [1, -1]
52+
recurrenceRule2.setPositions = [1]
53+
recurrenceRule2.hours = [14]
54+
recurrenceRule2.minutes = [30]
55+
recurrenceRule2.seconds = [0]
56+
recurrenceRule2.daysOfTheYear = [1]
57+
recurrenceRule2.daysOfTheMonth = [4]
58+
recurrenceRule2.weekdays = [.every(.monday), .nth(1, .wednesday)]
59+
recurrenceRule2.end = .afterDate(.distantFuture)
60+
61+
let recurrenceRule1JSON = try JSONEncoder().encode(recurrenceRule1)
62+
let recurrenceRule2JSON = try JSONEncoder().encode(recurrenceRule2)
63+
let decoded1 = try JSONDecoder().decode(Calendar.RecurrenceRule.self, from: recurrenceRule1JSON)
64+
let decoded2 = try JSONDecoder().decode(Calendar.RecurrenceRule.self, from: recurrenceRule2JSON)
65+
66+
#expect(recurrenceRule1 == decoded1)
67+
#expect(recurrenceRule2 == decoded2)
68+
#expect(recurrenceRule1 != recurrenceRule2)
69+
}
70+
}
71+
3172
@Test func yearlyRecurrenceInLunarCalendar() {
3273
// Find the first day of the lunar new year
3374
let start = Date(timeIntervalSince1970: 1726876800.0) // 2024-09-21T00:00:00-0000

0 commit comments

Comments
 (0)