-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TimeInterval and timespec reciprocal constructors
- Loading branch information
Showing
4 changed files
with
124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// TimeInterval.swift | ||
// OTCore | ||
// | ||
// Created by Steffan Andrews on 2021-01-09. | ||
// Copyright © 2020 Steffan Andrews. All rights reserved. | ||
|
||
import Foundation | ||
|
||
extension TimeInterval { | ||
|
||
/// OTCore: | ||
/// Convenience constructor from `timespec` | ||
public init(_ time: timespec) { | ||
|
||
self = time.doubleValue | ||
|
||
} | ||
|
||
} |
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,31 @@ | ||
// | ||
// TimeInterval Tests.swift | ||
// OTCore | ||
// | ||
// Created by Steffan Andrews on 2021-01-09. | ||
// Copyright © 2021 Steffan Andrews. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
#if !os(watchOS) | ||
|
||
import XCTest | ||
@testable import OTCore | ||
|
||
class TimeInterval_Tests: XCTestCase { | ||
|
||
override func setUp() { super.setUp() } | ||
override func tearDown() { super.tearDown() } | ||
|
||
func testTimeInterval_init_Timespec() { | ||
|
||
let ti = TimeInterval(timespec(tv_sec: 1, tv_nsec: 234_567_891)) | ||
|
||
XCTAssertEqual(ti, TimeInterval(1.234_567_891)) | ||
|
||
} | ||
|
||
} | ||
|
||
#endif |
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