luxon
luxon copied to clipboard
`engulfs` (anti-)alias: `during`?
I wasn't entirely sure what Interval.engulfs
did based on the documentation:
/**
* Return whether this Interval engulfs the start and end of the specified Interval.
* @param {Interval} other
* @return {boolean}
*/
The OED didn't help much, although I do find the connotations interesting:
The autumnal glutton who engulphs their [sc. oysters] gentle substances within his own.
(But if the engulphing [sic] is that complete, it would suggest that it didn't just contain the other interval, but contained it and then some?)
I ended up doing a unit test to check, and looking for the source code, and then thought "I can't be the only one with this literary impediment" so I wondered if you might consider creating an alias (or rather, an inverted alias) named during
? It would work well:
if (myDeliverySlot.during(myWorkDay)) {
console.log('I guess I'll have to come in late');
}
As for the name, during
seems clear and seems to fit well with equals
, overlaps
, abutsStart
, abutsEnd
, engulfs
?
I did not choose during
for three reasons:
- The semantics are flipped from engulfs, as you point out. If a engulfs b, b is during a. I think that's a bit less intuitive for programming -- you usually check of
container.contains(containee)
, notcontainee.isContainedBy(container)
orsuperset.containsSubset(subset)
, notsubset.isASubSetOf(superset)
. That's nothing more than convention, but it does seem common. -
during
doesn't have as clear of semantics about overlaps. If intervala
starts at 9 and ends at 10, andb
starts at 9:05 and ends at 10:05, is it "during"? At least to me, that's not obvious. - I also think
during
more naturally deals with DateTime instances, not other intervals, as in, "was 9:13:12.034 during intervala
?"
I do hear you on the point that engulfs
sort of implies that a
is bigger than b
, not just at least as big. I'm not sure during
helps with that though.
If we want a less obscure word, I think maybe something like fullyContains
. We could also just to clarify the docstring...
I'd be curious if lots of other people find this name confusing. I'm certainly not married to it and clarity is super important to an API like this.
We could also just to clarify the docstring...
:+1: on all points
Rather than waste time thinking of a better (anti-)name, the docstring sounds like a fast and effective solution, something like:
Returns true if this Interval fully contains the specified Interval, specifically if the intersect (of this Interval and the other Interval) is equal to the other Interval;
false
otherwise.
Sounds good to me.