Created
March 21, 2021 01:32
-
-
Save maakcode/57aa3224ff3f220a9dcd9f406407860e to your computer and use it in GitHub Desktop.
Composable TimeInterval extensions
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
extension TimeInterval { | |
static func milliseconds(_ value: Self) -> Self { | |
Self(value * 1e-3) | |
} | |
static func seconds(_ value: Self) -> Self { | |
Self(value) | |
} | |
static func minutes(_ value: Self) -> Self { | |
seconds(60) * value | |
} | |
static func hours(_ value: Self) -> Self { | |
minutes(60) * value | |
} | |
func miliseconds(_ value: Self) -> Self { | |
self + Self(value * 1e-3) | |
} | |
func seconds(_ value: Self) -> Self { | |
self + Self(value) | |
} | |
func minutes(_ value: Self) -> Self { | |
self + Self.seconds(60) * value | |
} | |
func hours(_ value: Self) -> Self { | |
self + Self.minutes(60) * value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Examples