import XCTest @testable import MultiSimAdmin final class TimestampTextTests: XCTestCase { private let calendar = Calendar(identifier: .gregorian) func testTodayOnlyShowsClockTime() { let output = TimestampText.short("2026-09-14 08:05:00", now: date(2026, 9, 14, 20, 0)) XCTAssertEqual(output, "08:05") } func testSameYearShowsMonthAndTime() { let output = TimestampText.short("2026-03-02 08:05:00", now: date(2026, 9, 14, 20, 0)) XCTAssertEqual(output, "03-02 08:05") } func testOtherYearFallsBackToDate() { let output = TimestampText.short("2025-12-31 23:59:00", now: date(2026, 9, 14, 20, 0)) XCTAssertEqual(output, "2025-12-31") } func testParsesEpochMilliseconds() { XCTAssertEqual(TimestampText.date(from: "1767484800000"), Date(timeIntervalSince1970: 1_767_484_800)) } func testParsesEpochSeconds() { XCTAssertEqual(TimestampText.date(from: "1767484800"), Date(timeIntervalSince1970: 1_767_484_800)) } func testZuluTimestampIsReadAsUTC() { let iso = try? XCTUnwrap(TimestampText.date(from: "2026-01-04T00:00:00Z")) XCTAssertEqual(iso, Date(timeIntervalSince1970: 1_767_484_800)) } func testUnparseableTextIsKeptAsIs() { XCTAssertEqual(TimestampText.short(" 刚刚 "), "刚刚") XCTAssertEqual(TimestampText.short(""), "") } private func date(_ year: Int, _ month: Int, _ day: Int, _ hour: Int, _ minute: Int) -> Date { var components = DateComponents() components.year = year components.month = month components.day = day components.hour = hour components.minute = minute return calendar.date(from: components)! } }