mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Attempt to fix bill view
This commit is contained in:
@@ -55,7 +55,6 @@ class Navigation
|
||||
* @param int $skip
|
||||
*
|
||||
* @return Carbon
|
||||
* @deprecated This method will be substituted by nextDateByInterval()
|
||||
*/
|
||||
public function addPeriod(Carbon $theDate, string $repeatFreq, int $skip = 0): Carbon
|
||||
{
|
||||
@@ -89,10 +88,10 @@ class Navigation
|
||||
|
||||
if (!array_key_exists($repeatFreq, $functionMap)) {
|
||||
Log::error(sprintf(
|
||||
'The periodicity %s is unknown. Choose one of available periodicity: %s',
|
||||
$repeatFreq,
|
||||
join(', ', array_keys($functionMap))
|
||||
));
|
||||
'The periodicity %s is unknown. Choose one of available periodicity: %s',
|
||||
$repeatFreq,
|
||||
join(', ', array_keys($functionMap))
|
||||
));
|
||||
return $theDate;
|
||||
}
|
||||
|
||||
@@ -342,6 +341,35 @@ class Navigation
|
||||
return $currentEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $period
|
||||
* @param Carbon $beginning
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function diffInPeriods(string $period, Carbon $beginning, Carbon $end): int
|
||||
{
|
||||
$map = [
|
||||
'daily' => 'diffInDays',
|
||||
'weekly' => 'diffInWeeks',
|
||||
'monthly' => 'diffInMonths',
|
||||
'quarterly' => 'diffInQuarters',
|
||||
'half-year' => 'diffInQuarters',
|
||||
'yearly' => 'diffInYears',
|
||||
];
|
||||
if (!array_key_exists($period, $map)) {
|
||||
app('log')->warning(sprintf('No diffInPeriods for period "%s"', $period));
|
||||
return 1;
|
||||
}
|
||||
$func = $map[$period];
|
||||
$diff = $beginning->$func($end);
|
||||
if ('half-year' === $period) {
|
||||
$diff = ceil($diff / 2);
|
||||
}
|
||||
return (int)$diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $theCurrentEnd
|
||||
* @param string $repeatFreq
|
||||
|
Reference in New Issue
Block a user