|
|
@ -11,24 +11,27 @@ import XCTest |
|
|
|
final class TimeAgoTests: XCTestCase { |
|
|
|
|
|
|
|
func testTimeAgoSince() { |
|
|
|
XCTAssertEqual(time_ago_since(Date.now), "now") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-2)), "now") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-3)), "3s") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-59)), "59s") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-60)), "1min") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-3599)), "59min") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-3600)), "1h") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-86399)), "23h") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-86400)), "1d") |
|
|
|
XCTAssertEqual(time_ago_since(Calendar.current.date(byAdding: .weekOfMonth, value: -1, to: Date.now)!.addingTimeInterval(1)), "6d") |
|
|
|
XCTAssertEqual(time_ago_since(Calendar.current.date(byAdding: .weekOfMonth, value: -1, to: Date.now)!), "1w") |
|
|
|
XCTAssertEqual(time_ago_since(Calendar.current.date(byAdding: .weekOfMonth, value: -2, to: Date.now)!), "2w") |
|
|
|
XCTAssertEqual(time_ago_since(Calendar.current.date(byAdding: .weekOfMonth, value: -3, to: Date.now)!), "3w") |
|
|
|
let locale = Locale(identifier: "en_US") |
|
|
|
let calendar = locale.calendar |
|
|
|
|
|
|
|
XCTAssertEqual(time_ago_since(Date.now, calendar), "now") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-2), calendar), "now") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-3), calendar), "3s") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-59), calendar), "59s") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-60), calendar), "1min") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-3599), calendar), "59min") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-3600), calendar), "1h") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-86399), calendar), "23h") |
|
|
|
XCTAssertEqual(time_ago_since(Date.now.addingTimeInterval(-86400), calendar), "1d") |
|
|
|
XCTAssertEqual(time_ago_since(calendar.date(byAdding: .weekOfMonth, value: -1, to: Date.now)!.addingTimeInterval(1), calendar), "6d") |
|
|
|
XCTAssertEqual(time_ago_since(calendar.date(byAdding: .weekOfMonth, value: -1, to: Date.now)!, calendar), "1w") |
|
|
|
XCTAssertEqual(time_ago_since(calendar.date(byAdding: .weekOfMonth, value: -2, to: Date.now)!, calendar), "2w") |
|
|
|
XCTAssertEqual(time_ago_since(calendar.date(byAdding: .weekOfMonth, value: -3, to: Date.now)!, calendar), "3w") |
|
|
|
// Not testing the 4-5 week boundary since how it is formatted depends on which month and year it is currently when this test executes. |
|
|
|
XCTAssertEqual(time_ago_since(Calendar.current.date(byAdding: .month, value: -1, to: Date.now)!), "1mo") |
|
|
|
XCTAssertEqual(time_ago_since(Calendar.current.date(byAdding: .year, value: -1, to: Date.now)!.addingTimeInterval(1)), "11mo") |
|
|
|
XCTAssertEqual(time_ago_since(Calendar.current.date(byAdding: .year, value: -1, to: Date.now)!), "1y") |
|
|
|
XCTAssertEqual(time_ago_since(Calendar.current.date(byAdding: .year, value: -1000, to: Date.now)!), "1,000y") |
|
|
|
XCTAssertEqual(time_ago_since(calendar.date(byAdding: .month, value: -1, to: Date.now)!, calendar), "1mo") |
|
|
|
XCTAssertEqual(time_ago_since(calendar.date(byAdding: .year, value: -1, to: Date.now)!.addingTimeInterval(1), calendar), "11mo") |
|
|
|
XCTAssertEqual(time_ago_since(calendar.date(byAdding: .year, value: -1, to: Date.now)!, calendar), "1y") |
|
|
|
XCTAssertEqual(time_ago_since(calendar.date(byAdding: .year, value: -1000, to: Date.now)!, calendar), "1,000y") |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|