Skip to content
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

engulfs (anti-)alias: during? #742

Open
AGBrown opened this issue Jul 17, 2020 · 3 comments
Open

engulfs (anti-)alias: during? #742

AGBrown opened this issue Jul 17, 2020 · 3 comments

Comments

@AGBrown
Copy link

AGBrown commented Jul 17, 2020

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?

@icambron
Copy link
Member

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.

@AGBrown
Copy link
Author

AGBrown commented Jul 18, 2020

We could also just to clarify the docstring...

👍 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.

@icambron
Copy link
Member

Sounds good to me.

0xBURP added a commit to 0xBURP/luxon that referenced this issue Jan 10, 2024
icambron pushed a commit that referenced this issue Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants