Skip to content

Commit

Permalink
Added tests for the new -timePassed method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaja Yting committed Aug 24, 2018
1 parent abe8423 commit 0f42588
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions EZSwiftExtensionsTests/DateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import XCTest
@testable import EZSwiftExtensions

class DateTests: XCTestCase {
// note that Date uses UTC in Date(timeIntervalSince1970: _)
Expand Down Expand Up @@ -171,6 +172,41 @@ class DateTests: XCTestCase {
XCTAssertEqual(fifteenYearsAgo?.timePassed(), "15 years ago")
}

func testTimePassedEnumBetweenDates() {

let today = Date()
let timePassedToday: TimePassed = today.timePassed()
XCTAssertEqual(timePassedToday, TimePassed.now)

let fifteenYearsAgo = Calendar.current.date(byAdding: .year, value: -15, to: today)
let timePassedFifteenYearsAgo: TimePassed = fifteenYearsAgo!.timePassed()
XCTAssertEqual(timePassedFifteenYearsAgo, TimePassed.year(15))

let twoMonthsAgo = Calendar.current.date(byAdding: .month, value: -2, to: today)
let timePassedTwoMonthsAgo: TimePassed = twoMonthsAgo!.timePassed()
XCTAssertEqual(timePassedTwoMonthsAgo, TimePassed.month(2))

let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: today)
let timePassedYesterday: TimePassed = yesterday!.timePassed()
XCTAssertEqual(timePassedYesterday, TimePassed.day(1))

let sixHoursAgo = Calendar.current.date(byAdding: .hour, value: -6, to: today)
let timePassedSixHoursAgo: TimePassed = sixHoursAgo!.timePassed()
XCTAssertEqual(timePassedSixHoursAgo, TimePassed.hour(6))

let thirteenMinutesAgo = Calendar.current.date(byAdding: .minute, value: -13, to: today)
let timePassedThirteenMinutesAgo: TimePassed = thirteenMinutesAgo!.timePassed()
XCTAssertEqual(timePassedThirteenMinutesAgo, TimePassed.minute(13))

let fiveSecondsAgo = Calendar.current.date(byAdding: .second, value: -5, to: today)
let timePassedFiveSecondsAgo: TimePassed = fiveSecondsAgo!.timePassed()
XCTAssertEqual(timePassedFiveSecondsAgo, TimePassed.second(5))

let oneSecondAgo = Calendar.current.date(byAdding: .second, value: -1, to: today)
let timePassedOneSecondAgo: TimePassed = oneSecondAgo!.timePassed()
XCTAssertEqual(timePassedOneSecondAgo, TimePassed.second(1))
}

func testIsPast() {
let beginningOfUnixTime = Date(timeIntervalSince1970: 0)
XCTAssertTrue(beginningOfUnixTime.isPast)
Expand Down

0 comments on commit 0f42588

Please sign in to comment.