spatie / period

Complex period comparisons
https://spatie.be/open-source
MIT License
1.56k stars 72 forks source link

Contains period #66

Closed adrianrudnik closed 3 years ago

adrianrudnik commented 3 years ago

Might be just brain-fart, but what is the correct way to see if a period is fully contained within a given other period?

A     [===]
B      [=]

Result: true

A     [===]
B    [==]

Result false

A     [===]
B      [==]

Result true

A     [===]
B     [===]

Result true

A     [===]
B        [===]

Result false

I just see a contains function that accepts a DateTimeInterface. Is it

$c = $a->overlapSingle($b);
return $b->equals($c);

or am I missing something with the precision that could go wrong?

brendt commented 3 years ago

That's the way I've done it in the past. We could make contains work with periods instead, but that would be a breaking change… I'll revisit this for the next version.