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

Compute differences between DateIntervals with timeInterval(to:) and dateInterval(to:) methods. #327

Closed
wants to merge 1 commit into from

Conversation

kielgillard
Copy link

@kielgillard kielgillard commented Nov 22, 2023

Implements #326.

Please read #326 where I explain how I expect this needs a pitch and review and asks what I should do next.

What?

Returns the seconds between self and dateInterval or nil if there is no difference in time between them.
For example, given these two intervals on a timeline:

|-----|  <-- time interval --> |-----|

Returns a negative time interval when self ends before dateInterval starts. A postive time interval indicates self starts after dateInterval ends.
A return value of 0 indicates self starts or ends where dateInterval ends or starts (in other words, they intersect at their opposing start/end moments):

|-----|-----|

A return value of nil indicates self and dateInterval do not have any time between them:

|--|-----|--|

Testing

I have included unit tests.

I was not able to build and test on Xcode 15b3:

No such module 'FoundationMacros'

As such, I am relying on any CI to build and test these changes.

@kielgillard kielgillard changed the title Add isBeside convenience method on DateInterval. Add isContinuous(with:) convenience method on DateInterval. Nov 22, 2023
@MaxDesiatov
Copy link
Member

@swift-ci test

@kielgillard kielgillard marked this pull request as draft November 23, 2023 04:34
@kielgillard kielgillard changed the title Add isContinuous(with:) convenience method on DateInterval. Compute differences between DateIntervals with timeInterval(to:) and dateInterval(to:) methods. Nov 24, 2023
@kielgillard kielgillard changed the title Compute differences between DateIntervals with timeInterval(to:) and dateInterval(to:) methods. Compute differences between DateIntervals with timeInterval(to:) and dateInterval(to:) methods. Nov 24, 2023
@kielgillard kielgillard marked this pull request as ready for review November 24, 2023 22:56

let d11 = testInterval11.dateInterval(to: testInterval11)
XCTAssertEqual(d11, nil)
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have broken these down into separate test functions (one expecting non-nil and another nil intervals) but I implemented it like this to follow the lead of pre-existing test functions.

@iCharlesHu
Copy link
Contributor

Hi @kielgillard! It looks like you are proposing a change to TimeInterval's public interface? Any changes to Foundation's API surface requires API Proposal: https://github.com/apple/swift-foundation/blob/main/Proposals/0000-template.md

Could you go ahead and draft up a proposal for this change so we can review them both here and on the forum? Thanks!

@iCharlesHu iCharlesHu added the API Change Any changes to Foundation's public API surface label Nov 27, 2023
@kielgillard
Copy link
Author

@iCharlesHu Hello, thank you for the comment. Would still love any feedback you might have!

I'm now working on a proposal in #331 and the implementation can now be found in #330.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Change Any changes to Foundation's public API surface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants