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
Add isBetween method to date extension #248
Conversation
/// - Parameter endDate: endDate date to compare self to. | ||
/// - Parameter includeBounds: true if the start and end date should be included (default is true) | ||
/// - Returns: true if the date is between the two given dates. | ||
public func isBetween(_ startDate: Date, _ endDate: Date, includeBounds: Bool = true) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with this. Clean & well documented 🎉 I'm just curious if we don't need the extension and can use:
let date1 = Date()
let date2 = Date()
let date3 = Date()
let bool = (date1...date2).contains(date3)
I agree having the bounds check makes this easier though. I would like to see it default to false
though. Because between
is technically not inclusive. What do you think @Bennx?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SD10 Of cause it does make more sense to have it set to false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also like the Range idea. Lets see if i can figure that out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bennx The implementation doesn't need to be changed. It's fine as is. This could be more performant actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bennx No, we shouldn't add that extension. This is already possible and would conflict with the Swift standard library.
Codecov Report
@@ Coverage Diff @@
## master #248 +/- ##
==========================================
+ Coverage 93.63% 93.66% +0.03%
==========================================
Files 97 97
Lines 5544 5572 +28
==========================================
+ Hits 5191 5219 +28
Misses 353 353
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bennx Can you add a CHANGELOG entry for this that follows the same format we are using?
@SD10 hope the format fits. |
@Bennx This would go under the |
@SD10 Got it. Cheers! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Bennx for seeing this from start to finish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a
isBetween
method to the date extension which can be used to determine if a date is between two given dates including or excluding the given dates itself. Default is to include the dates itself.Checklist