Description
Note for wanderers
The understanding of this issue evolved since its creation. I've started working on a proposal at #331. The current implementation can now be found at #330.
Original comment
I was reviewing some code today that checked two date intervals, say A
and B
, were arranged like this on a timeline:
----|---A---|---B---|----
These intervals intersect, but it would be nice to easily check how they intersect; if they "touch" at their boundaries; if the intervals are "beside" each other. This resulted in the following implementation:
func isBeside(_ other: DateInterval) -> Bool {
self.start == other.end || self.end == other.start
}
Naming aside*, how viable would this such a contribution be as an incredibly tiny but nice convenience method on DateInterval
?
It seems it would have to go through evolution which, as the tiniest of conveniences, would be practically embarrassing. While I think it would be delightful to have this quality assured convenience available when you realise you need it, I do not have any data that demands its presence in Foundation, either. I did no more than a search of GitHub for Swift or Objective-C code for date intervals, dates and times. There's seems to be no obvious or compelling third party redundancy to solve. Is this a dead end? What can I do next?
* pun not intended.
EDIT: Having thought a bit more about the name, I would say "beside" and "sidedness" is a bad choice / metaphor because it ignores that these kinds of intervals do in fact intersect, it just they intersect at the very first and last moments. An alternative could be isContinuous
.