Hacker News new | ask | show | jobs
by windpower 1550 days ago
Swift is pretty good at this. e.g.:

  Task.sleep(nanoseconds: 3e11)
1 comments

In swift I quite like DispatchTimeInterval's approach [1] (see Enumeration Cases). In most of my projects I end up adding a simple extension to TimeInterval to get the same behavior. Which makes reasoning about time very simple eg:

  Date().advanced(by: .hours(2) + .seconds(10))
I'm honestly not sure why TimeInterval doesn't include this representation by default.

1. https://developer.apple.com/documentation/dispatch/dispatcht...