SE-0329: Clock, Instant, Date, and Duration

The main reason is that you cannot avoid seconds when talking about temporal durations, because seconds are the fundamental unit of all physical time measurement.

Yes, people can do multiplication of factors to get longer units, but I believe it's worthwhile to discourage that by omitting the convenience methods to do so. This also speaks to the larger problem that .hours(3) means different things depending on which clock you're using, suggesting strongly that Duration should be a Clock associated type.

ETA: For situations like these in my own code, I go so far as to add these methods, but then mark them as unavailable so I can explain why they're the wrong thing to use:

extension Duration {
    @available(*, unavailable, message: "Use clock-specific APIs for creating durations that are measured in units longer than seconds")
    static func minutes(_ duration: Double) -> Self { ... }
    // etc
}

This is also why my Time library explicitly names this type as the SISecond.

If you'd like to discuss this more, I think that'd be better served for the pitch thread, so we can keep this one focused on reviews.

14 Likes