Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
57 lines
1.7 KiB
Swift
57 lines
1.7 KiB
Swift
//
|
|
// DateExtensionsTests.swift
|
|
// RSSuperTests
|
|
//
|
|
// Created by Mike Freno on 3/29/26.
|
|
//
|
|
|
|
import XCTest
|
|
@testable import RSSuper
|
|
|
|
final class DateExtensionsTests: XCTestCase {
|
|
|
|
func testMillisecondsSince1970() {
|
|
let date = Date(timeIntervalSince1970: 1609459200)
|
|
XCTAssertEqual(date.millisecondsSince1970, 1609459200000)
|
|
}
|
|
|
|
func testInitFromMilliseconds() {
|
|
let date = Date(millisecondsSince1970: 1609459200000)!
|
|
XCTAssertEqual(date.timeIntervalSince1970, 1609459200)
|
|
}
|
|
|
|
func testSecondsSince1970() {
|
|
let date = Date(timeIntervalSince1970: 1609459200)
|
|
XCTAssertEqual(date.secondsSince1970, 1609459200)
|
|
}
|
|
|
|
func testInitFromSeconds() {
|
|
let date = Date(secondsSince1970: 1609459200)!
|
|
XCTAssertEqual(date.timeIntervalSince1970, 1609459200)
|
|
}
|
|
|
|
func testISO8601String() {
|
|
let date = Date(timeIntervalSince1970: 1609459200)
|
|
let isoString = date.iso8601String
|
|
|
|
// Verify it's a valid ISO8601 string
|
|
let formatter = ISO8601DateFormatter()
|
|
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
|
XCTAssertNotNil(formatter.date(from: isoString))
|
|
}
|
|
|
|
func testInitFromISO8601String() {
|
|
let formatter = ISO8601DateFormatter()
|
|
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
|
let isoString = formatter.string(from: Date(timeIntervalSince1970: 1609459200))
|
|
|
|
let date = Date(iso8601String: isoString)!
|
|
XCTAssertEqual(date.timeIntervalSince1970, 1609459200, accuracy: 1.0)
|
|
}
|
|
|
|
func testInvalidISO8601String() {
|
|
let date = Date(iso8601String: "not-a-date")
|
|
XCTAssertNil(date)
|
|
}
|
|
}
|