Small code quality improvements.

This commit is contained in:
James Cole
2018-07-14 23:22:08 +02:00
parent 5dad569d62
commit f1462dbd3d
7 changed files with 49 additions and 38 deletions

View File

@@ -33,6 +33,30 @@ use Log;
*/
trait DateCalculation
{
/**
* @param Carbon $start
* @param Carbon $end
*
* @return string
*/
protected function calculateStep(Carbon $start, Carbon $end): string
{
$step = '1D';
$months = $start->diffInMonths($end);
if ($months > 3) {
$step = '1W'; // @codeCoverageIgnore
}
if ($months > 24) {
$step = '1M'; // @codeCoverageIgnore
}
if ($months > 100) {
$step = '1Y'; // @codeCoverageIgnore
}
return $step;
}
/**
* Returns the number of days between the two given dates.
* - If today is within the two dates, give the number of days between today and the end date.
@@ -111,7 +135,7 @@ trait DateCalculation
while ($count < 12) {
$format = $current->format('Y-m-d');
$loop[$format] = app('navigation')->periodShow($current, $range);
$current = app('navigation')->endOfPeriod($current, $range);
$current = app('navigation')->endOfPeriod($current, $range);
++$count;
$current->addDay();
}