Skip to content

Commit b05f5d2

Browse files
committed
Upgrade ICU to 74
1 parent 9e7732b commit b05f5d2

File tree

4 files changed

+66
-56
lines changed

4 files changed

+66
-56
lines changed

Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ var dependencies: [Package.Dependency] {
104104
} else {
105105
[
106106
.package(
107-
url: "https://github.com/apple/swift-foundation-icu",
108-
from: "0.0.9"),
107+
url: "https://github.com/apple/swift-foundation-icu.git",
108+
exact: "0.0.10"),
109109
.package(
110110
url: "https://github.com/apple/swift-foundation",
111111
revision: "acae3d26b69113cec2db7772b4144ab9558241db")

Tests/Foundation/TestDateFormatter.swift

+35-35
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ class TestDateFormatter: XCTestCase {
7979
func test_dateStyleShort() {
8080

8181
let timestamps = [
82-
-31536000 : "1/1/69, 12:00AM" , 0.0 : "1/1/70, 12:00AM", 31536000 : "1/1/71, 12:00AM",
83-
2145916800 : "1/1/38, 12:00AM", 1456272000 : "2/24/16, 12:00AM", 1456358399 : "2/24/16, 11:59PM",
84-
1452574638 : "1/12/16, 4:57AM", 1455685038 : "2/17/16, 4:57AM", 1458622638 : "3/22/16, 4:57AM",
85-
1459745838 : "4/4/16, 4:57AM", 1462597038 : "5/7/16, 4:57AM", 1465534638 : "6/10/16, 4:57AM",
86-
1469854638 : "7/30/16, 4:57AM", 1470718638 : "8/9/16, 4:57AM", 1473915438 : "9/15/16, 4:57AM",
87-
1477285038 : "10/24/16, 4:57AM", 1478062638 : "11/2/16, 4:57AM", 1482641838 : "12/25/16, 4:57AM"
82+
-31536000 : "1/1/69, 12:00 AM" , 0.0 : "1/1/70, 12:00 AM", 31536000 : "1/1/71, 12:00 AM",
83+
2145916800 : "1/1/38, 12:00 AM", 1456272000 : "2/24/16, 12:00 AM", 1456358399 : "2/24/16, 11:59 PM",
84+
1452574638 : "1/12/16, 4:57 AM", 1455685038 : "2/17/16, 4:57 AM", 1458622638 : "3/22/16, 4:57 AM",
85+
1459745838 : "4/4/16, 4:57 AM", 1462597038 : "5/7/16, 4:57 AM", 1465534638 : "6/10/16, 4:57 AM",
86+
1469854638 : "7/30/16, 4:57 AM", 1470718638 : "8/9/16, 4:57 AM", 1473915438 : "9/15/16, 4:57 AM",
87+
1477285038 : "10/24/16, 4:57 AM", 1478062638 : "11/2/16, 4:57 AM", 1482641838 : "12/25/16, 4:57 AM"
8888
]
8989

9090
let f = DateFormatter()
@@ -100,7 +100,7 @@ class TestDateFormatter: XCTestCase {
100100
let testDate = Date(timeIntervalSince1970: timestamp)
101101
let sf = f.string(from: testDate)
102102

103-
XCTAssertEqual(sf, stringResult)
103+
XCTAssertEqual(sf.normalizingICUSeparator(), stringResult)
104104
}
105105

106106
}
@@ -145,12 +145,12 @@ class TestDateFormatter: XCTestCase {
145145
func test_dateStyleLong() {
146146

147147
let timestamps = [
148-
-31536000 : "January 1, 1969 at 12:00:00AM GMT" , 0.0 : "January 1, 1970 at 12:00:00AM GMT", 31536000 : "January 1, 1971 at 12:00:00AM GMT",
149-
2145916800 : "January 1, 2038 at 12:00:00AM GMT", 1456272000 : "February 24, 2016 at 12:00:00AM GMT", 1456358399 : "February 24, 2016 at 11:59:59PM GMT",
150-
1452574638 : "January 12, 2016 at 4:57:18AM GMT", 1455685038 : "February 17, 2016 at 4:57:18AM GMT", 1458622638 : "March 22, 2016 at 4:57:18AM GMT",
151-
1459745838 : "April 4, 2016 at 4:57:18AM GMT", 1462597038 : "May 7, 2016 at 4:57:18AM GMT", 1465534638 : "June 10, 2016 at 4:57:18AM GMT",
152-
1469854638 : "July 30, 2016 at 4:57:18AM GMT", 1470718638 : "August 9, 2016 at 4:57:18AM GMT", 1473915438 : "September 15, 2016 at 4:57:18AM GMT",
153-
1477285038 : "October 24, 2016 at 4:57:18AM GMT", 1478062638 : "November 2, 2016 at 4:57:18AM GMT", 1482641838 : "December 25, 2016 at 4:57:18AM GMT"
148+
-31536000 : "January 1, 1969 at 12:00:00 AM GMT" , 0.0 : "January 1, 1970 at 12:00:00 AM GMT", 31536000 : "January 1, 1971 at 12:00:00 AM GMT",
149+
2145916800 : "January 1, 2038 at 12:00:00 AM GMT", 1456272000 : "February 24, 2016 at 12:00:00 AM GMT", 1456358399 : "February 24, 2016 at 11:59:59 PM GMT",
150+
1452574638 : "January 12, 2016 at 4:57:18 AM GMT", 1455685038 : "February 17, 2016 at 4:57:18 AM GMT", 1458622638 : "March 22, 2016 at 4:57:18 AM GMT",
151+
1459745838 : "April 4, 2016 at 4:57:18 AM GMT", 1462597038 : "May 7, 2016 at 4:57:18 AM GMT", 1465534638 : "June 10, 2016 at 4:57:18 AM GMT",
152+
1469854638 : "July 30, 2016 at 4:57:18 AM GMT", 1470718638 : "August 9, 2016 at 4:57:18 AM GMT", 1473915438 : "September 15, 2016 at 4:57:18 AM GMT",
153+
1477285038 : "October 24, 2016 at 4:57:18 AM GMT", 1478062638 : "November 2, 2016 at 4:57:18 AM GMT", 1482641838 : "December 25, 2016 at 4:57:18 AM GMT"
154154
]
155155

156156
let f = DateFormatter()
@@ -164,7 +164,7 @@ class TestDateFormatter: XCTestCase {
164164
let testDate = Date(timeIntervalSince1970: timestamp)
165165
let sf = f.string(from: testDate)
166166

167-
XCTAssertEqual(sf, stringResult)
167+
XCTAssertEqual(sf.normalizingICUSeparator(), stringResult)
168168
}
169169

170170
}
@@ -282,37 +282,37 @@ class TestDateFormatter: XCTestCase {
282282

283283
let formats: [String: (DateFormatter.Style, DateFormatter.Style)] = [
284284
"": (.none, .none),
285-
"h:mma": (.none, .short),
286-
"h:mm:ssa": (.none, .medium),
287-
"h:mm:ssa z": (.none, .long),
288-
"h:mm:ssa zzzz": (.none, .full),
285+
"h:mm a": (.none, .short),
286+
"h:mm:ss a": (.none, .medium),
287+
"h:mm:ss a z": (.none, .long),
288+
"h:mm:ss a zzzz": (.none, .full),
289289
"M/d/yy": (.short, .none),
290-
"M/d/yy, h:mma": (.short, .short),
291-
"M/d/yy, h:mm:ssa": (.short, .medium),
292-
"M/d/yy, h:mm:ssa z": (.short, .long),
293-
"M/d/yy, h:mm:ssa zzzz": (.short, .full),
290+
"M/d/yy, h:mm a": (.short, .short),
291+
"M/d/yy, h:mm:ss a": (.short, .medium),
292+
"M/d/yy, h:mm:ss a z": (.short, .long),
293+
"M/d/yy, h:mm:ss a zzzz": (.short, .full),
294294
"MMM d, y": (.medium, .none),
295-
"MMM d, y 'at' h:mma": (.medium, .short),
296-
"MMM d, y 'at' h:mm:ssa": (.medium, .medium),
297-
"MMM d, y 'at' h:mm:ssa z": (.medium, .long),
298-
"MMM d, y 'at' h:mm:ssa zzzz": (.medium, .full),
295+
"MMM d, y 'at' h:mm a": (.medium, .short),
296+
"MMM d, y 'at' h:mm:ss a": (.medium, .medium),
297+
"MMM d, y 'at' h:mm:ss a z": (.medium, .long),
298+
"MMM d, y 'at' h:mm:ss a zzzz": (.medium, .full),
299299
"MMMM d, y": (.long, .none),
300-
"MMMM d, y 'at' h:mma": (.long, .short),
301-
"MMMM d, y 'at' h:mm:ssa": (.long, .medium),
302-
"MMMM d, y 'at' h:mm:ssa z": (.long, .long),
303-
"MMMM d, y 'at' h:mm:ssa zzzz": (.long, .full),
300+
"MMMM d, y 'at' h:mm a": (.long, .short),
301+
"MMMM d, y 'at' h:mm:ss a": (.long, .medium),
302+
"MMMM d, y 'at' h:mm:ss a z": (.long, .long),
303+
"MMMM d, y 'at' h:mm:ss a zzzz": (.long, .full),
304304
"EEEE, MMMM d, y": (.full, .none),
305-
"EEEE, MMMM d, y 'at' h:mma": (.full, .short),
306-
"EEEE, MMMM d, y 'at' h:mm:ssa": (.full, .medium),
307-
"EEEE, MMMM d, y 'at' h:mm:ssa z": (.full, .long),
308-
"EEEE, MMMM d, y 'at' h:mm:ssa zzzz": (.full, .full),
305+
"EEEE, MMMM d, y 'at' h:mm a": (.full, .short),
306+
"EEEE, MMMM d, y 'at' h:mm:ss a": (.full, .medium),
307+
"EEEE, MMMM d, y 'at' h:mm:ss a z": (.full, .long),
308+
"EEEE, MMMM d, y 'at' h:mm:ss a zzzz": (.full, .full),
309309
]
310310

311311
for (dateFormat, styles) in formats {
312312
f.dateStyle = styles.0
313313
f.timeStyle = styles.1
314314

315-
XCTAssertEqual(f.dateFormat!, dateFormat)
315+
XCTAssertEqual(f.dateFormat!.normalizingICUSeparator(), dateFormat)
316316
}
317317
}
318318

Tests/Foundation/TestDateIntervalFormatter.swift

+20-19
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ extension String {
4040
}
4141

4242
func assertContainsInOrder(requiresLastToBeAtEnd: Bool = false, _ substrings: String...) {
43-
let result = containsInOrder(requiresLastToBeAtEnd: requiresLastToBeAtEnd, substrings)
44-
XCTAssert(result == .success, "String '\(self)' (must end with: \(requiresLastToBeAtEnd)) does not contain in sequence: \(substrings) — reason: \(result)")
43+
let replaced = self.normalizingICUSeparator()
44+
let result = replaced.containsInOrder(requiresLastToBeAtEnd: requiresLastToBeAtEnd, substrings)
45+
XCTAssert(result == .success, "String '\(replaced)' (must end with: \(requiresLastToBeAtEnd)) does not contain in sequence: \(substrings) — reason: \(result)")
4546
}
4647
}
4748

@@ -69,44 +70,44 @@ class TestDateIntervalFormatter: XCTestCase {
6970
let newer = Date(timeIntervalSinceReferenceDate: 3e9)
7071

7172
let result = formatter.string(from: older, to: newer)
72-
result.assertContainsInOrder("January 1", "2001", "12:00:00AM", "Greenwich Mean Time",
73-
"January 25", "2096", "5:20:00AM", "Greenwich Mean Time")
73+
result.assertContainsInOrder("January 1", "2001", "12:00:00 AM", "Greenwich Mean Time",
74+
"January 25", "2096", "5:20:00 AM", "Greenwich Mean Time")
7475
}
7576

7677
func testStringFromDateToDateAcrossThreeMillionSeconds() {
7778
let older = Date(timeIntervalSinceReferenceDate: 0)
7879
let newer = Date(timeIntervalSinceReferenceDate: 3e6)
7980

8081
let result = formatter.string(from: older, to: newer)
81-
result.assertContainsInOrder("January 1", "2001", "12:00:00AM", "Greenwich Mean Time",
82-
"February 4", "2001", "5:20:00PM", "Greenwich Mean Time")
82+
result.assertContainsInOrder("January 1", "2001", "12:00:00 AM", "Greenwich Mean Time",
83+
"February 4", "2001", "5:20:00 PM", "Greenwich Mean Time")
8384
}
8485

8586
func testStringFromDateToDateAcrossThreeBillionSecondsReversed() {
8687
let older = Date(timeIntervalSinceReferenceDate: 0)
8788
let newer = Date(timeIntervalSinceReferenceDate: 3e9)
8889

8990
let result = formatter.string(from: newer, to: older)
90-
result.assertContainsInOrder("January 25", "2096", "5:20:00AM", "Greenwich Mean Time",
91-
"January 1", "2001", "12:00:00AM", "Greenwich Mean Time")
91+
result.assertContainsInOrder("January 25", "2096", "5:20:00 AM", "Greenwich Mean Time",
92+
"January 1", "2001", "12:00:00 AM", "Greenwich Mean Time")
9293
}
9394

9495
func testStringFromDateToDateAcrossThreeMillionSecondsReversed() {
9596
let older = Date(timeIntervalSinceReferenceDate: 0)
9697
let newer = Date(timeIntervalSinceReferenceDate: 3e6)
9798

9899
let result = formatter.string(from: newer, to: older)
99-
result.assertContainsInOrder("February 4", "2001", "5:20:00PM", "Greenwich Mean Time",
100-
"January 1", "2001", "12:00:00AM", "Greenwich Mean Time")
100+
result.assertContainsInOrder("February 4", "2001", "5:20:00 PM", "Greenwich Mean Time",
101+
"January 1", "2001", "12:00:00 AM", "Greenwich Mean Time")
101102
}
102103

103104
func testStringFromDateToSameDate() throws {
104105
let date = Date(timeIntervalSinceReferenceDate: 3e6)
105106

106107
// For a range from a date to itself, we represent the date only once, with no interdate separator.
107108
let result = formatter.string(from: date, to: date)
108-
result.assertContainsInOrder(requiresLastToBeAtEnd: true, "February 4", "2001", "5:20:00PM", "Greenwich Mean Time")
109-
109+
result.assertContainsInOrder(requiresLastToBeAtEnd: true, "February 4", "2001", "5:20:00 PM", "Greenwich Mean Time")
110+
110111
let firstFebruary = try XCTUnwrap(result.range(of: "February"))
111112
XCTAssertNil(result[firstFebruary.upperBound...].range(of: "February")) // February appears only once.
112113
}
@@ -115,8 +116,8 @@ class TestDateIntervalFormatter: XCTestCase {
115116
let interval = DateInterval(start: Date(timeIntervalSinceReferenceDate: 0), duration: 3e6)
116117

117118
let result = try XCTUnwrap(formatter.string(from: interval))
118-
result.assertContainsInOrder("January 1", "2001", "12:00:00AM", "Greenwich Mean Time",
119-
"February 4", "2001", "5:20:00PM", "Greenwich Mean Time")
119+
result.assertContainsInOrder("January 1", "2001", "12:00:00 AM", "Greenwich Mean Time",
120+
"February 4", "2001", "5:20:00 PM", "Greenwich Mean Time")
120121
}
121122

122123
func testStringFromDateToDateAcrossOneWeek() {
@@ -193,7 +194,7 @@ class TestDateIntervalFormatter: XCTestCase {
193194
let newer = Date(timeIntervalSinceReferenceDate: 3600 * 5)
194195

195196
let result = formatter.string(from: older, to: newer)
196-
result.assertContainsInOrder(requiresLastToBeAtEnd: true, "January", "1", "2001", "12:00:00AM", "5:00:00AM", "GMT")
197+
result.assertContainsInOrder(requiresLastToBeAtEnd: true, "January", "1", "2001", "12:00:00 AM", "5:00:00 AM", "GMT")
197198

198199
let firstJanuary = try XCTUnwrap(result.range(of: "January"))
199200
XCTAssertNil(result[firstJanuary.upperBound...].range(of: "January")) // January appears only once.
@@ -205,8 +206,8 @@ class TestDateIntervalFormatter: XCTestCase {
205206

206207
let result = formatter.string(from: older, to: newer)
207208
result.assertContainsInOrder(requiresLastToBeAtEnd: true,
208-
"January", "1", "2001", "10:00:00PM", "Greenwich Mean Time",
209-
"January", "2", "2001", "3:00:00AM", "Greenwich Mean Time")
209+
"January", "1", "2001", "10:00:00 PM", "Greenwich Mean Time",
210+
"January", "2", "2001", "3:00:00 AM", "Greenwich Mean Time")
210211
}
211212
}
212213

@@ -215,8 +216,8 @@ class TestDateIntervalFormatter: XCTestCase {
215216
let newer = Date(timeIntervalSinceReferenceDate: 3600 * 18)
216217

217218
let result = formatter.string(from: older, to: newer)
218-
result.assertContainsInOrder(requiresLastToBeAtEnd: true, "January", "1", "2001", "12:00:00AM", "6:00:00PM", "GMT")
219-
219+
result.assertContainsInOrder(requiresLastToBeAtEnd: true, "January", "1", "2001", "12:00:00 AM", "6:00:00 PM", "GMT")
220+
220221
let firstJanuary = try XCTUnwrap(result.range(of: "January"))
221222
XCTAssertNil(result[firstJanuary.upperBound...].range(of: "January")) // January appears only once.
222223
}

Tests/Foundation/TestUtils.swift

+9
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,12 @@ func ensureFiles(_ fileNames: [String]) -> Bool {
4242
}
4343
return result
4444
}
45+
46+
extension String {
47+
/// This function normalizes whitespace used by ICU to `\u{020f}`.
48+
///
49+
/// ICU uses `\u{202f}` and `\u{020f}` interchangeably.
50+
public func normalizingICUSeparator() -> String {
51+
replacingOccurrences(of: "\u{202f}", with: " ")
52+
}
53+
}

0 commit comments

Comments
 (0)