Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DispatchTimeInterval methods to TaggedTime #25

Merged
merged 2 commits into from
May 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Sources/TaggedTime/TaggedTime.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Dispatch
import Foundation
import Tagged

Expand Down Expand Up @@ -31,12 +32,17 @@ extension Tagged where Tag == MillisecondsTag, RawValue: BinaryFloatingPoint {
}
}

extension Tagged where Tag == MillisecondsTag, RawValue == Int {
extension Tagged where Tag == MillisecondsTag, RawValue: BinaryInteger {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also loosened this constraint to match what we have for SecondsTag.

/// Converts milliseconds into `TimeInterval`, which is measured in seconds.
public var timeInterval: TimeInterval {
return self.map(TimeInterval.init).timeInterval
}

/// Converts milliseconds into `DispatchTimeInterval`.
public var dispatchTimeInterval: DispatchTimeInterval {
return .milliseconds(Int(self.rawValue))
}

/// Converts milliseconds into `Date`, which is measured in seconds.
public var date: Date {
return Date(timeIntervalSince1970: self.timeInterval)
Expand All @@ -56,6 +62,11 @@ extension Tagged where Tag == SecondsTag, RawValue: BinaryInteger {
return TimeInterval(Int64(self.rawValue))
}

/// Converts seconds into `DispatchTimeInterval`.
public var dispatchTimeInterval: DispatchTimeInterval {
return .seconds(Int(self.rawValue))
}

/// Converts seconds in `Date`.
public var date: Date {
return Date(timeIntervalSince1970: self.timeInterval)
Expand Down