-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Foundation | ||
|
||
extension Date { | ||
/// Seconds from date | ||
public var second: Int { return Calendar.current.component(.second, from: self) } | ||
|
||
/// Minutes from date | ||
public var minute: Int { return Calendar.current.component(.minute, from: self) } | ||
|
||
/// Hours from date in 24-hour format | ||
public var hour: Int { return Calendar.current.component(.hour, from: self) } | ||
|
||
/// Days from date | ||
public var day: Int { return Calendar.current.component(.day, from: self) } | ||
|
||
/// Months from date | ||
public var month: Int { return Calendar.current.component(.month, from: self) } | ||
|
||
/// Year from date | ||
public var year: Int { return Calendar.current.component(.year, from: self) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// DateTests.swift | ||
// ACKategories | ||
// | ||
// Created by Jakub Olejník on 13/06/2018. | ||
// Copyright © 2018 Ackee, s.r.o. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import ACKategories | ||
|
||
final class DateTests: XCTestCase { | ||
|
||
var date: Date! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
date = Date() | ||
} | ||
|
||
func testCorrectSecond() { | ||
let df = DateFormatter() | ||
df.dateFormat = "s" | ||
|
||
XCTAssertEqual(Int(df.string(from: date)), date.second) | ||
} | ||
|
||
func testCorrectMinute() { | ||
let df = DateFormatter() | ||
df.dateFormat = "m" | ||
|
||
XCTAssertEqual(Int(df.string(from: date)), date.minute) | ||
} | ||
|
||
func testCorrectHour() { | ||
let df = DateFormatter() | ||
df.dateFormat = "H" | ||
|
||
XCTAssertEqual(Int(df.string(from: date)), date.hour) | ||
} | ||
|
||
func testCorrectDay() { | ||
let df = DateFormatter() | ||
df.dateFormat = "d" | ||
|
||
XCTAssertEqual(Int(df.string(from: date)), date.day) | ||
} | ||
|
||
func testCorrectMonth() { | ||
let df = DateFormatter() | ||
df.dateFormat = "M" | ||
|
||
XCTAssertEqual(Int(df.string(from: date)), date.month) | ||
} | ||
|
||
func testCorrectYear() { | ||
let df = DateFormatter() | ||
df.dateFormat = "YYYY" | ||
|
||
XCTAssertEqual(Int(df.string(from: date)), date.year) | ||
} | ||
} | ||
|