             let older = Date(timeIntervalSinceReferenceDate: 0)
             let newer = Date(timeIntervalSinceReferenceDate: 3600 * 24 * 7)
             
-            XCTAssertEqual(formatter.string(from: older, to: newer),
-                           "Jan 1 – 8")
+            let result = formatter.string(from: older, to: newer)
+            XCTAssert(result.containsInOrder(requiresLastToBeAtEnd: true, "Jan", "1", "8"))
         }
         
         do {
             let older = Date(timeIntervalSinceReferenceDate: 3600 * 24 * 28)
             let newer = Date(timeIntervalSinceReferenceDate: 3600 * 24 * 34)
             
-            XCTAssertEqual(formatter.string(from: older, to: newer),
-                           "Jan 29 – 4")
+            let result = formatter.string(from: older, to: newer)
+            XCTAssert(result.containsInOrder(requiresLastToBeAtEnd: true, "Jan", "29", "4"))
+            XCTAssertNil(result.range(of: "Feb"))
         }
     }
     #endif

        let older = Date(timeIntervalSinceReferenceDate: 0)
        let newer = Date(timeIntervalSinceReferenceDate: 3e9)
        
        XCTAssertEqual(formatter.string(from: older, to: newer),
                       "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)
        
        XCTAssertEqual(formatter.string(from: older, to: newer),
                       "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)
        
        XCTAssertEqual(formatter.string(from: newer, to: older),
                       "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)
        
        XCTAssertEqual(formatter.string(from: newer, to: older),
                       "February 4, 2001, 5:20:00 PM Greenwich Mean Time – January 1, 2001, 12:00:00 AM Greenwich Mean Time")
    }
    
    func testStringFromDateToSameDate() {
        let date = Date(timeIntervalSinceReferenceDate: 3e6)
        
        // For a range from a date to itself, we represent the date only once, with no interdate separator.
        XCTAssertEqual(formatter.string(from: date, to: date),
                       "February 4, 2001, 5:20:00 PM Greenwich Mean Time")
    }
    
    func testStringFromDateIntervalAcrossThreeMillionSeconds() {
        let interval = DateInterval(start: Date(timeIntervalSinceReferenceDate: 0), duration: 3e6)
        
        XCTAssertEqual(formatter.string(from: interval),
                       "January 1, 2001, 12:00:00 AM Greenwich Mean Time – February 4, 2001, 5:20:00 PM Greenwich Mean Time")
    }
    
    func testStringFromDateToDateAcrossOneWeek() {

    #endif
#endif

extension String {
    func containsInOrder(requiresLastToBeAtEnd: Bool = false, _ substrings: String...) -> Bool {
        var foundRange: Range<String.Index> = startIndex ..< startIndex
        for substring in substrings {
            if let newRange = range(of: substring, options: [], range: foundRange.upperBound..<endIndex, locale: nil) {
                foundRange = newRange
            } else {
                return false
            }
        }
        
        if requiresLastToBeAtEnd {
            return foundRange.upperBound == endIndex
        } else {
            return true
        }
    }
}

class TestDateIntervalFormatter: XCTestCase {
    private var formatter: DateIntervalFormatter!
    
