Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whole differences should return integers #81

Open
davedelong opened this issue Apr 6, 2024 · 1 comment
Open

Whole differences should return integers #81

davedelong opened this issue Apr 6, 2024 · 1 comment

Comments

@davedelong
Copy link
Owner

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
Copy link
Owner Author

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
}

@davedelong davedelong added this to the 1.1 milestone Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant