Write CalendarExtensionsTests.

This commit is contained in:
Brent Simmons 2024-05-18 12:06:43 -07:00
parent 5ec78cbbde
commit 0ec83de1de
1 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,39 @@
//
// CalendarExtensionsTests.swift
//
//
// Created by Brent Simmons on 5/18/24.
//
import XCTest
final class CalendarExtensionsTests: XCTestCase {
// MARK: - Test dateIsToday
func testDateIsToday() {
var date = Date()
// The below could fail if midnight hits between the above line and the following line! This will probably never happen, but if it does, check to see if this was run at midnight.
XCTAssertTrue(Calendar.dateIsToday(date))
date = Date.distantPast
XCTAssertFalse(Calendar.dateIsToday(date))
date = Date.distantFuture
XCTAssertFalse(Calendar.dateIsToday(date))
date = Date().byAdding(days: 14)
XCTAssertFalse(Calendar.dateIsToday(date))
date = Date().bySubtracting(days: 67)
XCTAssertFalse(Calendar.dateIsToday(date))
let calendar = Calendar.current
let yesterday = calendar.date(byAdding: .day, value: -1, to: Date())!
XCTAssertFalse(Calendar.dateIsToday(yesterday))
let tomorrow = calendar.date(byAdding: .day, value: 1, to: Date())!
XCTAssertFalse(Calendar.dateIsToday(tomorrow))
}
}