spatie / period

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

Visualization bugs #86

Closed tsterker closed 3 years ago

tsterker commented 3 years ago

ℹ️ Apologies for the brief "issue dump", but my time is currently limited and I wanted to report this already. Maybe I'll find time to provide details and/or PRs.

Also, thanks for this great package!


I found some bugs in the visualizer. My setup is the following:

use Spatie\Period\Visualizer;
use Spatie\Period\Period;

$v = new Visualizer(['width' => 10]);

$periods = [ /* ... */ ];

echo "\n" . $v->visualize($periods) . "\n";

1. Visualization of less than 2 periods

⚠️ max(): When only one parameter is given, it must be an array

// CASE: No periods
$periods = [];

// CASE: Only one period
$periods = [
  Period::make(now(), now()->addDay())
];

2. Visualization of period spanning no more than one day

⚠️ Division by zero

$periods = [
  Period::make(now(), now()),
  Period::make(now(), now())
];

3. Single-day periods sometimes not rendered

Single-day periods not renderd

$periods = [
     \Spatie\Period\Period::make(now(), now()),
     \Spatie\Period\Period::make(now(), now()->addDay()),
     \Spatie\Period\Period::make(now(), now()),
];
0              
1    [========]
2  

Single-day periods rendered depending on the width

Varying the visualization width seems to affect the outcome.

Assume the following periods:

$periods = [
    Period::make(now(), now()),
    Period::make(now()->addDay(), now()->addDay()),
    Period::make(now()->subDays(38), now()->addDays(2)),
];

Width: 50 (all periods rendered)

$v = new Visualizer(['width' => 50]);
0                                                   =  
1                                                    = 
2    [================================================]

Width: 60 (one period "gone")

$v = new Visualizer(['width' => 60]);
0                                                                
1                                                              = 
2    [==========================================================]
brendt commented 3 years ago

Feel free to submit a PR when you've got the time, I don't think I'll be looking into this anytime soon myself.