From 0ec83de1de24cbd7ea444c852d1609b349559cb3 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 18 May 2024 12:06:43 -0700 Subject: [PATCH] Write CalendarExtensionsTests. --- .../CalendarExtensionsTests.swift | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 FoundationExtras/Tests/FoundationExtrasTests/CalendarExtensionsTests.swift diff --git a/FoundationExtras/Tests/FoundationExtrasTests/CalendarExtensionsTests.swift b/FoundationExtras/Tests/FoundationExtrasTests/CalendarExtensionsTests.swift new file mode 100644 index 000000000..c3fdcfff5 --- /dev/null +++ b/FoundationExtras/Tests/FoundationExtrasTests/CalendarExtensionsTests.swift @@ -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)) + } + }