     #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!
     

        let newer = Date(timeIntervalSinceReferenceDate: 3600 * 24 * 60)
        
        // Minimization shouldn't do anything since this spans more than a month
        XCTAssertEqual(formatter.string(from: older, to: newer),
                       "Jan 1 – Mar 2")
    }
    #endif
    
    func testStringFromDateToDateAcrossFiveHours() {
        do {
            let older = Date(timeIntervalSinceReferenceDate: 0)
            let newer = Date(timeIntervalSinceReferenceDate: 3600 * 5)
            
            XCTAssertEqual(formatter.string(from: older, to: newer),
                           "January 1, 2001, 12:00:00 AM GMT – 5:00:00 AM GMT")
        }
        
        do {

            
            XCTAssertEqual(formatter.string(from: older, to: newer),
                           "January 1, 2001, 10:00:00 PM Greenwich Mean Time – January 2, 2001, 3:00:00 AM Greenwich Mean Time")
            let result = formatter.string(from: older, to: newer)
            XCTAssert(result.containsInOrder(requiresLastToBeAtEnd: true, "January", "1", "2001", "10:00:00 AM", "5:00:00 AM"))
        }
    }
    
    func testStringFromDateToDateAcrossEighteenHours() throws {
        let older = Date(timeIntervalSinceReferenceDate: 0)
        let newer = Date(timeIntervalSinceReferenceDate: 3600 * 18)
        
        let result = formatter.string(from: older, to: newer)
        XCTAssert(result.containsInOrder(requiresLastToBeAtEnd: true, "January", "1", "2001", "12:00:00 AM", "6:00:00 PM"))
        
        let firstJanuary = try result.range(of: "January").unwrapped()
        XCTAssertNil(result[firstJanuary.upperBound...].range(of: "January")) // January appears only once.
    }
    
    static var allTests: [(String, (TestDateIntervalFormatter) -> () throws -> Void)] {
