Skip to content

Commit

Permalink
Upgrade ICU to 74
Browse files Browse the repository at this point in the history
  • Loading branch information
iCharlesHu committed Jul 31, 2024
1 parent 9e7732b commit 2e8ac1e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var dependencies: [Package.Dependency] {
[
.package(
url: "https://github.com/apple/swift-foundation-icu",
from: "0.0.9"),
from: "0.0.10"),
.package(
url: "https://github.com/apple/swift-foundation",
revision: "acae3d26b69113cec2db7772b4144ab9558241db")
Expand Down
70 changes: 35 additions & 35 deletions Tests/Foundation/TestDateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class TestDateFormatter: XCTestCase {
func test_dateStyleShort() {

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

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

XCTAssertEqual(sf, stringResult)
XCTAssertEqual(sf.normalizingICUSeparator(), stringResult)
}

}
Expand Down Expand Up @@ -145,12 +145,12 @@ class TestDateFormatter: XCTestCase {
func test_dateStyleLong() {

let timestamps = [
-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",
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",
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",
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",
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",
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"
-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",
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",
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",
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",
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",
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"
]

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

XCTAssertEqual(sf, stringResult)
XCTAssertEqual(sf.normalizingICUSeparator(), stringResult)
}

}
Expand Down Expand Up @@ -282,37 +282,37 @@ class TestDateFormatter: XCTestCase {

let formats: [String: (DateFormatter.Style, DateFormatter.Style)] = [
"": (.none, .none),
"h:mma": (.none, .short),
"h:mm:ssa": (.none, .medium),
"h:mm:ssa z": (.none, .long),
"h:mm:ssa zzzz": (.none, .full),
"h:mm a": (.none, .short),
"h:mm:ss a": (.none, .medium),
"h:mm:ss a z": (.none, .long),
"h:mm:ss a zzzz": (.none, .full),
"M/d/yy": (.short, .none),
"M/d/yy, h:mma": (.short, .short),
"M/d/yy, h:mm:ssa": (.short, .medium),
"M/d/yy, h:mm:ssa z": (.short, .long),
"M/d/yy, h:mm:ssa zzzz": (.short, .full),
"M/d/yy, h:mm a": (.short, .short),
"M/d/yy, h:mm:ss a": (.short, .medium),
"M/d/yy, h:mm:ss a z": (.short, .long),
"M/d/yy, h:mm:ss a zzzz": (.short, .full),
"MMM d, y": (.medium, .none),
"MMM d, y 'at' h:mma": (.medium, .short),
"MMM d, y 'at' h:mm:ssa": (.medium, .medium),
"MMM d, y 'at' h:mm:ssa z": (.medium, .long),
"MMM d, y 'at' h:mm:ssa zzzz": (.medium, .full),
"MMM d, y 'at' h:mm a": (.medium, .short),
"MMM d, y 'at' h:mm:ss a": (.medium, .medium),
"MMM d, y 'at' h:mm:ss a z": (.medium, .long),
"MMM d, y 'at' h:mm:ss a zzzz": (.medium, .full),
"MMMM d, y": (.long, .none),
"MMMM d, y 'at' h:mma": (.long, .short),
"MMMM d, y 'at' h:mm:ssa": (.long, .medium),
"MMMM d, y 'at' h:mm:ssa z": (.long, .long),
"MMMM d, y 'at' h:mm:ssa zzzz": (.long, .full),
"MMMM d, y 'at' h:mm a": (.long, .short),
"MMMM d, y 'at' h:mm:ss a": (.long, .medium),
"MMMM d, y 'at' h:mm:ss a z": (.long, .long),
"MMMM d, y 'at' h:mm:ss a zzzz": (.long, .full),
"EEEE, MMMM d, y": (.full, .none),
"EEEE, MMMM d, y 'at' h:mma": (.full, .short),
"EEEE, MMMM d, y 'at' h:mm:ssa": (.full, .medium),
"EEEE, MMMM d, y 'at' h:mm:ssa z": (.full, .long),
"EEEE, MMMM d, y 'at' h:mm:ssa zzzz": (.full, .full),
"EEEE, MMMM d, y 'at' h:mm a": (.full, .short),
"EEEE, MMMM d, y 'at' h:mm:ss a": (.full, .medium),
"EEEE, MMMM d, y 'at' h:mm:ss a z": (.full, .long),
"EEEE, MMMM d, y 'at' h:mm:ss a zzzz": (.full, .full),
]

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

XCTAssertEqual(f.dateFormat!, dateFormat)
XCTAssertEqual(f.dateFormat!.normalizingICUSeparator(), dateFormat)
}
}

Expand Down
39 changes: 20 additions & 19 deletions Tests/Foundation/TestDateIntervalFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ extension String {
}

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

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

let result = formatter.string(from: older, to: newer)
result.assertContainsInOrder("January 1", "2001", "12:00:00AM", "Greenwich Mean Time",
"January 25", "2096", "5:20:00AM", "Greenwich Mean Time")
result.assertContainsInOrder("January 1", "2001", "12:00:00 AM", "Greenwich Mean Time",
"January 25", "2096", "5:20:00 AM", "Greenwich Mean Time")
}

func testStringFromDateToDateAcrossThreeMillionSeconds() {
let older = Date(timeIntervalSinceReferenceDate: 0)
let newer = Date(timeIntervalSinceReferenceDate: 3e6)

let result = formatter.string(from: older, to: newer)
result.assertContainsInOrder("January 1", "2001", "12:00:00AM", "Greenwich Mean Time",
"February 4", "2001", "5:20:00PM", "Greenwich Mean Time")
result.assertContainsInOrder("January 1", "2001", "12:00:00 AM", "Greenwich Mean Time",
"February 4", "2001", "5:20:00 PM", "Greenwich Mean Time")
}

func testStringFromDateToDateAcrossThreeBillionSecondsReversed() {
let older = Date(timeIntervalSinceReferenceDate: 0)
let newer = Date(timeIntervalSinceReferenceDate: 3e9)

let result = formatter.string(from: newer, to: older)
result.assertContainsInOrder("January 25", "2096", "5:20:00AM", "Greenwich Mean Time",
"January 1", "2001", "12:00:00AM", "Greenwich Mean Time")
result.assertContainsInOrder("January 25", "2096", "5:20:00 AM", "Greenwich Mean Time",
"January 1", "2001", "12:00:00 AM", "Greenwich Mean Time")
}

func testStringFromDateToDateAcrossThreeMillionSecondsReversed() {
let older = Date(timeIntervalSinceReferenceDate: 0)
let newer = Date(timeIntervalSinceReferenceDate: 3e6)

let result = formatter.string(from: newer, to: older)
result.assertContainsInOrder("February 4", "2001", "5:20:00PM", "Greenwich Mean Time",
"January 1", "2001", "12:00:00AM", "Greenwich Mean Time")
result.assertContainsInOrder("February 4", "2001", "5:20:00 PM", "Greenwich Mean Time",
"January 1", "2001", "12:00:00 AM", "Greenwich Mean Time")
}

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

// For a range from a date to itself, we represent the date only once, with no interdate separator.
let result = formatter.string(from: date, to: date)
result.assertContainsInOrder(requiresLastToBeAtEnd: true, "February 4", "2001", "5:20:00PM", "Greenwich Mean Time")
result.assertContainsInOrder(requiresLastToBeAtEnd: true, "February 4", "2001", "5:20:00 PM", "Greenwich Mean Time")

let firstFebruary = try XCTUnwrap(result.range(of: "February"))
XCTAssertNil(result[firstFebruary.upperBound...].range(of: "February")) // February appears only once.
}
Expand All @@ -115,8 +116,8 @@ class TestDateIntervalFormatter: XCTestCase {
let interval = DateInterval(start: Date(timeIntervalSinceReferenceDate: 0), duration: 3e6)

let result = try XCTUnwrap(formatter.string(from: interval))
result.assertContainsInOrder("January 1", "2001", "12:00:00AM", "Greenwich Mean Time",
"February 4", "2001", "5:20:00PM", "Greenwich Mean Time")
result.assertContainsInOrder("January 1", "2001", "12:00:00 AM", "Greenwich Mean Time",
"February 4", "2001", "5:20:00 PM", "Greenwich Mean Time")
}

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

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

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

let result = formatter.string(from: older, to: newer)
result.assertContainsInOrder(requiresLastToBeAtEnd: true,
"January", "1", "2001", "10:00:00PM", "Greenwich Mean Time",
"January", "2", "2001", "3:00:00AM", "Greenwich Mean Time")
"January", "1", "2001", "10:00:00 PM", "Greenwich Mean Time",
"January", "2", "2001", "3:00:00 AM", "Greenwich Mean Time")
}
}

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

let result = formatter.string(from: older, to: newer)
result.assertContainsInOrder(requiresLastToBeAtEnd: true, "January", "1", "2001", "12:00:00AM", "6:00:00PM", "GMT")
result.assertContainsInOrder(requiresLastToBeAtEnd: true, "January", "1", "2001", "12:00:00 AM", "6:00:00 PM", "GMT")

let firstJanuary = try XCTUnwrap(result.range(of: "January"))
XCTAssertNil(result[firstJanuary.upperBound...].range(of: "January")) // January appears only once.
}
Expand Down
9 changes: 9 additions & 0 deletions Tests/Foundation/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ func ensureFiles(_ fileNames: [String]) -> Bool {
}
return result
}

extension String {
/// This function normalizes whitespace used by ICU to `\u{020f}`.
///
/// ICU uses `\u{202f}` and `\u{020f}` interchangeably.
public func normalizingICUSeparator() -> String {
replacingOccurrences(of: "\u{202f}", with: " ")
}
}

0 comments on commit 2e8ac1e

Please sign in to comment.