davedelong / time

Robust and type-safe date and time calculations for Swift
MIT License
2.32k stars 77 forks source link

Whole differences should return integers #81

Open davedelong opened 7 months ago

davedelong commented 7 months ago

The differenceInWhole... functions should just return Int values. The underlying TimeDifference, because of the nature of the computation, will only have a single represented value, so the extra indirection is unnecessary.

This could be implemented by adding the new Int-returning methods but marking them as @_disfavoredOverload; that would mean existing code would continue to compile without issues and would not require modifications.

Eventually when Time reaches 2.0 status, the @_disfavoredOverload attribute could swap from the Int-returning method to the TimeDifference-returning method, because that's a source/API-breaking change, which is appropriate for a major version update.

davedelong commented 7 months ago

Example:

public func differenceInWholeYears(to other: Self) -> TimeDifference<Year, Year> { ... }

@_disfavoredOverload
public func differenceInWholeYears(to other: Self) -> Int {
    let difference: TimeDifference<Year, Year> = self.differenceInWholeYears(to: other)
    return difference.years
}