TF-2871 Fix incorrect ISO8601 date string to date conversion
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import XCTest
|
||||
|
||||
@testable import Runner
|
||||
|
||||
class DateConversionTests: XCTestCase {
|
||||
|
||||
func testConvertValidISO8601StringToDate() {
|
||||
let validDateString = "2024-05-20T22:54:57.958"
|
||||
|
||||
let date = validDateString.convertISO8601StringToDate()
|
||||
XCTAssertNotNil(date, "Date should not be nil")
|
||||
|
||||
let calendar = Calendar.current
|
||||
let expectedComponents = DateComponents(year: 2024, month: 5, day: 20, hour: 22, minute: 54, second: 57, nanosecond: 958000000)
|
||||
let expectedDate = calendar.date(from: expectedComponents)
|
||||
XCTAssertEqual(date, expectedDate, "Converted date does not match expected date")
|
||||
}
|
||||
|
||||
func testInvalidISO8601String() {
|
||||
let invalidDateString = "Invalid Date String"
|
||||
|
||||
let date = invalidDateString.convertISO8601StringToDate()
|
||||
XCTAssertNil(date, "The conversion should return nil for an invalid date string.")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user