
So to summarise: Kotlin doesn't allow (1) to create ranges of dates by default, and (2) to check if one range is fully included in another range. In addition to that, Range defines a contains(Range) method, hence why the second example compiles correctly.

However, core-ktx defines a function to transform a ClosedRange to a Range, and that function is. Now, apparently the Android stdlib defines its own concept of Range, which is unrelated to Kotlin's ClosedRange (as one does not extend the other). Now, ClosedRange defines some contains methods, but none of them accepts another ClosedRange as a parameter, hence your error. So assuming that you can do a.b to create a ClosedRange (which is something not available by default in the Kotlin stdlib, but maybe core-ktx defines its own extension for that), according to the Kotlin documentation, x in y gets translated to y.contains(x). (other.start in this & other.endInclusive in this)ĭisclaimer: I'm not an Android developer and have no experience with re, so take my answer with a pinch of salt. (other.isEmpty() & (other.start in this || other.endInclusive in this)) || Other.isEmpty() || (other.start in this & other.endInclusive in this) Operator fun > ntains(other: ClosedRange): Boolean = Other.start in this & other.endInclusive in this operator fun > ntains(other: ClosedRange): Boolean = You can define your own extension function for ClosedRange if you want, with behavior that depends on how you want to interpret the meaning of an empty range being contained. I'm not sure what you mean by circumventing it. What would it mean for a negative-direction ClosedRange to be in another ClosedRange? It's empty, but it has a span. This makes the concept of a ClosedRange containing another more ambiguous than with Ranges. One difference between the two classes is that the Android Range class forbids a range with the start value higher than the lower, but Kotlin ClosedRange allows it.

Or maybe the Kotlin developers have a higher criteria for what functions are useful enough to include in the standard library. Maybe the Kotlin developers decided the meaning of a range being in another range might be ambiguous, and the Android developers didn't. These two libraries are made by different companies and were made with different goals in mind, so you can't necessarily call it an oversight.

ClosedRange is part of the Kotlin standard library.
