Skip to content

Instantly share code, notes, and snippets.

@FlorianMielke
Last active July 5, 2023 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlorianMielke/284ba01b9715584edf4eca8ad70f457b to your computer and use it in GitHub Desktop.
Save FlorianMielke/284ba01b9715584edf4eca8ad70f457b to your computer and use it in GitHub Desktop.
A simple convenience extension to Int when working with TimeInterval
import Foundation
public extension Int {
var seconds: TimeInterval { TimeInterval(self) }
var second: TimeInterval { seconds }
var minutes: TimeInterval { seconds * 60 }
var minute: TimeInterval { minutes }
var hours: TimeInterval { minutes * 60 }
var hour: TimeInterval { hours }
var day: TimeInterval { hours * 24 }
var days: TimeInterval { day }
}
@FlorianMielke
Copy link
Author

Instead of writing

let eightHours = 28_800

you write:

let eightHours = 8.hours

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment