spatie / period

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

touchesWith() does not take precision into consideration #67

Closed tania-pets closed 3 years ago

tania-pets commented 3 years ago

Seems that touchesWith() will always return true if the compared periods are in the same day, even if the times are not really touched and the precision is SECOND.

Example:

$a = Period::make('2018-01-01 06:30:00', '2018-01-01 07:30:00');
$b = Period::make('2018-01-01 09:00:00', '2018-01-01 10:00:00');
$overlap = $a->touchesWith($b);
(true)

This leads to gap() function not detecting the gap for such cases.

freekmurze commented 3 years ago

We accept a PR that adds a test and a fix for this.

kukko commented 3 years ago

I'll be happy to try to solve this issue.

freekmurze commented 3 years ago

Warning: the principal author of the package thinks that this is a difficult change: https://twitter.com/brendt_gd/status/1313127606640881671

kukko commented 3 years ago

I also created a pull request (#69) which not add precision parameter, but it is calculate the difference between the dates correctly.

brendt commented 3 years ago

Fixed with https://github.com/spatie/period/releases/tag/1.5.1