luxon icon indicating copy to clipboard operation
luxon copied to clipboard

`engulfs` (anti-)alias: `during`?

Open AGBrown opened this issue 4 years ago • 3 comments

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?

AGBrown avatar Jul 17 '20 21:07 AGBrown

I did not choose during for three reasons:

  1. 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), not containee.isContainedBy(container) or superset.containsSubset(subset), not subset.isASubSetOf(superset). That's nothing more than convention, but it does seem common.
  2. during doesn't have as clear of semantics about overlaps. If interval a starts at 9 and ends at 10, and b starts at 9:05 and ends at 10:05, is it "during"? At least to me, that's not obvious.
  3. I also think during more naturally deals with DateTime instances, not other intervals, as in, "was 9:13:12.034 during interval a?"

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.

icambron avatar Jul 17 '20 22:07 icambron

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.

AGBrown avatar Jul 18 '20 00:07 AGBrown

Sounds good to me.

icambron avatar Jul 18 '20 01:07 icambron