Skip to content

Commit

Permalink
tests for date + typo rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandin committed Sep 23, 2020
1 parent a8fdf84 commit 18f950d
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 34 deletions.
33 changes: 0 additions & 33 deletions Sources/Toolbox/Exstentions/Date+Extensions.swift

This file was deleted.

File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions Sources/Toolbox/Extensions/Date+Extensions.swift
@@ -0,0 +1,33 @@

import UIKit

public extension Date {

var isDateYesterday: Bool {
Calendar.current.isDateInYesterday(self)
}

var isDateToday: Bool {
return Calendar.current.isDateInToday(self)
}

var isDateWeekend: Bool {
Calendar.current.isDateInWeekend(self)
}

var isDateTomorrow: Bool {
return Calendar.current.isDateInTomorrow(self)
}

func isDateThisWeek(with date: Date) -> Bool {
return Calendar.current.isDate(date, equalTo: self, toGranularity: .weekday)
}

func isDateThisMonth(with date: Date) -> Bool {
return Calendar.current.isDate(date, equalTo: self, toGranularity: .month)
}

func isDateThisYear(with date: Date) -> Bool {
return Calendar.current.isDate(date, equalTo: self, toGranularity: .year)
}
}
File renamed without changes.
File renamed without changes.
24 changes: 23 additions & 1 deletion Tests/ToolboxTests/ToolboxTests.swift
Expand Up @@ -67,6 +67,27 @@ final class ToolboxTests: XCTestCase {
XCTAssertEqual(stringToSubscript[7...], "789")
XCTAssertEqual(stringToSubscript[3...5], "345")
}

// MARK: Date Testing

func testDates() {

let isoDateYesterday = "2020-09-22T10:43:31.227Z"
let isoDateLastYear = "2015-03-22T10:43:31.227Z"

let today = Date()

let dateYesterday = Formatters.isoDateFormatter.date(from: isoDateYesterday) ?? Date()
let dateLastYear = Formatters.isoDateFormatter.date(from: isoDateLastYear) ?? Date()

XCTAssertTrue(dateYesterday.isDateYesterday)
XCTAssertFalse(today.isDateTomorrow)
XCTAssertTrue(today.isDateToday)

XCTAssertFalse(dateYesterday.isDateThisWeek(with: today))
XCTAssertFalse(dateLastYear.isDateThisMonth(with: today))
XCTAssertFalse(dateLastYear.isDateThisYear(with: today))
}

static var allTests = [
("testArrayRemoveIsRemovedTrue", testArrayRemoveIsRemovedTrue),
Expand All @@ -75,6 +96,7 @@ final class ToolboxTests: XCTestCase {
("testStringDigitsOnlyTrue", testStringDigitsOnlyTrue),
("testStringToNilTrue", testStringToNilTrue),
("testStringToIntTrue", testStringToIntTrue),
("testStringSubscriptTrue", testStringSubscriptTrue)
("testStringSubscriptTrue", testStringSubscriptTrue),
("testDates", testDates)
]
}

0 comments on commit 18f950d

Please sign in to comment.