-
Notifications
You must be signed in to change notification settings - Fork 103
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
Local date range #189
base: master
Are you sure you want to change the base?
Local date range #189
Conversation
range and progression semantics with the LocalDate and DatePeriod classes.
We have a similar request, but for |
@dkhalanskyjb I've had a use case for this, though it's more of a convenience having a dedicated A few other use cases off the top of my head:
|
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.
- Could you also make the range an implementation of
Collection
? See https://youtrack.jetbrains.com/issue/KT-36932/Let-Progression-classes-implement-Collection-to-reduce-time-when-iterates-over-IntRange-when-cast-to-Iterable - All API entries (classes, functions, properties) need separate tests, a KDoc, and a usage sample.
Something I came across that's not exactly an issue in the library, but is a usability question when using the library in IntelliJ that I'm wondering if there's a good answer for. Because Kotlin automatically imports (localDate1..localDate2).forEach {
// some code in here
}
This is easily solved by importing |
@PeterAttardo, maybe this issue can be solved if |
@dkhalanskyjb I was hoping not to have to touch the |
Co-authored-by: Dmitry Khalanskiy <[email protected]>
Co-authored-by: Dmitry Khalanskiy <[email protected]>
Co-authored-by: Dmitry Khalanskiy <[email protected]>
Co-authored-by: Dmitry Khalanskiy <[email protected]>
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.
Compilation fails for me, and when I fix it, the getSize
test fails.
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.
Other than the small naming issue, I think it's good to go!
core/common/src/LocalDateRange.kt
Outdated
/** | ||
* Returns true iff every element in [elements] is a member of the progression. | ||
*/ | ||
override fun containsAll(elements: Collection<LocalDate>): Boolean = elements.all(::contains) |
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.
Due to Collection
being a covariant type, we cannot trust the actual type of element in elements
to be LocalDate
here.
Please add a test checking e.g. (dateProgression as Collection<*>).containsAll(listOf(Any())
. It should be false, but not fail.
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.
Is this a deeper issue than at first appears? The signature of the methods implies no such unsafety, however after digging into it I can see that the methods in AbstractCollection
are annotated with @UnsafeVariance
, while the methods in UByteArray
contain explicit type checks. I suppose it's a concession to Java compatibility where the contains
methods take instances of Object
instead of a typed parameter?
In any event, I'll copy the type check logic from UByteArray
and add the test.
…ession.contains()
…d of IllegalArgumentException
This pull request enables Kotlin range and progression semantics with the LocalDate and DatePeriod classes. Its implementation borrows from the patterns used for
IntRange
.Example: