Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Restore old behavior
James Cole3913fa5086f9
diff --git a/app/Api/V1/Controllers/Summary/BasicController.php b/app/Api/V1/Controllers/Summary/BasicController.phpindex 0ac913f809..89f402b9f4 100644--- a/app/Api/V1/Controllers/Summary/BasicController.php+++ b/app/Api/V1/Controllers/Summary/BasicController.php@@ -281,7 +281,7 @@ class BasicController extends Controller$spentInCurrency = $row['sum'];$leftToSpend = bcadd($amount, $spentInCurrency);- $days = $today->diffInDays($end) + 1;+ $days = (int)$today->diffInDays($end, true) + 1;$perDay = '0';if (0 !== $days && bccomp($leftToSpend, '0') > -1) {$perDay = bcdiv($leftToSpend, (string)$days);diff --git a/app/Api/V1/Requests/Data/DateRequest.php b/app/Api/V1/Requests/Data/DateRequest.phpindex 416ee8793a..04a19ee4d4 100644--- a/app/Api/V1/Requests/Data/DateRequest.php+++ b/app/Api/V1/Requests/Data/DateRequest.php@@ -46,7 +46,7 @@ class DateRequest extends FormRequest{$start = $this->getCarbonDate('start');$end = $this->getCarbonDate('end');- if ($start->diffInYears($end) > 5) {+ if ($start->diffInYears($end, true) > 5) {throw new FireflyException('Date range out of range.');}diff --git a/app/Api/V2/Controllers/Summary/BasicController.php b/app/Api/V2/Controllers/Summary/BasicController.phpindex c166f3573b..672768f2a4 100644--- a/app/Api/V2/Controllers/Summary/BasicController.php+++ b/app/Api/V2/Controllers/Summary/BasicController.php@@ -298,7 +298,7 @@ class BasicController extends Controllerapp('log')->debug(sprintf('Amount left is %s', $left));// how much left per day?- $days = $today->diffInDays($end) + 1;+ $days = (int) $today->diffInDays($end,true) + 1;$perDay = '0';$perDayNative = '0';if (0 !== $days && bccomp($left, '0') > -1) {diff --git a/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php b/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.phpindex 39263ad0c6..15a98a4487 100644--- a/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php+++ b/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php@@ -110,7 +110,7 @@ class AppendBudgetLimitPeriods extends Commandreturn 'daily';}// is weekly- if ('1' === $limit->start_date->format('N') && '7' === $limit->end_date->format('N') && 6 === $limit->end_date->diffInDays($limit->start_date)) {+ if ('1' === $limit->start_date->format('N') && '7' === $limit->end_date->format('N') && 6 === (int)$limit->end_date->diffInDays($limit->start_date, true)) {return 'weekly';}@@ -129,7 +129,7 @@ class AppendBudgetLimitPeriods extends Commandif (in_array($limit->start_date->format('j-n'), $start, true) // start of quarter&& in_array($limit->end_date->format('j-n'), $end, true) // end of quarter- && 2 === $limit->start_date->diffInMonths($limit->end_date)+ && 2 === (int)$limit->start_date->diffInMonths($limit->end_date, true)) {return 'quarterly';}@@ -139,7 +139,7 @@ class AppendBudgetLimitPeriods extends Commandif (in_array($limit->start_date->format('j-n'), $start, true) // start of quarter&& in_array($limit->end_date->format('j-n'), $end, true) // end of quarter- && 5 === $limit->start_date->diffInMonths($limit->end_date)+ && 5 === (int)$limit->start_date->diffInMonths($limit->end_date, true)) {return 'half_year';}diff --git a/app/Generator/Report/ReportGeneratorFactory.php b/app/Generator/Report/ReportGeneratorFactory.phpindex fcb97f979f..9d74f758ba 100644--- a/app/Generator/Report/ReportGeneratorFactory.php+++ b/app/Generator/Report/ReportGeneratorFactory.php@@ -40,12 +40,12 @@ class ReportGeneratorFactory{$period = 'Month';// more than two months date difference means year report.- if ($start->diffInMonths($end) > 1) {+ if ($start->diffInMonths($end, true) > 1) {$period = 'Year';}- // more than one year date difference means multi year report.- if ($start->diffInMonths($end) > 12) {+ // more than one year date difference means multi-year report.+ if ($start->diffInMonths($end, true) > 12) {$period = 'MultiYear';}diff --git a/app/Handlers/Events/UserEventHandler.php b/app/Handlers/Events/UserEventHandler.phpindex 8f414e6b97..1dfb2cef9f 100644--- a/app/Handlers/Events/UserEventHandler.php+++ b/app/Handlers/Events/UserEventHandler.php@@ -405,7 +405,7 @@ class UserEventHandler}// clean up old entries (6 months)$carbon = Carbon::createFromFormat('Y-m-d H:i:s', $preference[$index]['time']);- if (false !== $carbon && $carbon->diffInMonths(today()) > 6) {+ if (false !== $carbon && $carbon->diffInMonths(today(), true) > 6) {app('log')->debug(sprintf('Entry for %s is very old, remove it.', $row['ip']));unset($preference[$index]);}diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.phpindex cfda4df609..30ac8a2f52 100644--- a/app/Http/Controllers/HomeController.php+++ b/app/Http/Controllers/HomeController.php@@ -97,10 +97,10 @@ class HomeController extends Controllerapp('log')->debug('Range is now marked as "custom".');}- $diff = $start->diffInDays($end) + 1;+ $diff = $start->diffInDays($end, true) + 1;if ($diff > 50) {- $request->session()->flash('warning', (string)trans('firefly.warning_much_data', ['days' => $diff]));+ $request->session()->flash('warning', (string)trans('firefly.warning_much_data', ['days' => (int)$diff]));}$request->session()->put('is_custom_range', $isCustomRange);diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.phpindex 9b29489e83..d8c1ac707f 100644--- a/app/Http/Controllers/Json/BoxController.php+++ b/app/Http/Controllers/Json/BoxController.php@@ -113,7 +113,7 @@ class BoxController extends Controller$spentAmount = $spent[$currency->id]['sum'] ?? '0';app('log')->debug(sprintf('Spent for default currency for all budgets in this period: %s', $spentAmount));- $days = $today->between($start, $end) ? $today->diffInDays($start) + 1 : $end->diffInDays($start) + 1;+ $days = (int)($today->between($start, $end) ? $today->diffInDays($start, true) + 1 : $end->diffInDays($start, true) + 1);app('log')->debug(sprintf('Number of days left: %d', $days));$spentPerDay = bcdiv($spentAmount, (string)$days);app('log')->debug(sprintf('Available to spend per day: %s', $spentPerDay));diff --git a/app/Jobs/WarnAboutBills.php b/app/Jobs/WarnAboutBills.phpindex e7f1915dfd..e79e05ea58 100644--- a/app/Jobs/WarnAboutBills.php+++ b/app/Jobs/WarnAboutBills.php@@ -128,7 +128,7 @@ class WarnAboutBills implements ShouldQueue$today = clone $this->date;$carbon = clone $bill->{$field};- return $today->diffInDays($carbon, false);+ return (int) $today->diffInDays($carbon);}private function sendWarning(Bill $bill, string $field): voiddiff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.phpindex 6f8fcf45b5..8a511cba34 100644--- a/app/Repositories/Budget/BudgetRepository.php+++ b/app/Repositories/Budget/BudgetRepository.php@@ -132,7 +132,7 @@ class BudgetRepository implements BudgetRepositoryInterfacecontinue;}- $total = $limit->start_date->diffInDays($limit->end_date) + 1; // include the day itself.+ $total = $limit->start_date->diffInDays($limit->end_date, true) + 1; // include the day itself.$days = $this->daysInOverlap($limit, $start, $end);$amount = bcmul(bcdiv($limit->amount, (string)$total), (string)$days);$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], $amount);@@ -183,21 +183,21 @@ class BudgetRepository implements BudgetRepositoryInterface// |-----------|// |----------------|if ($start->gte($limit->start_date) && $end->lte($limit->end_date)) {- return $start->diffInDays($end) + 1; // add one day+ return (int) $start->diffInDays($end, true) + 1; // add one day}// limit starts earlier and limit ends first:// |-----------|// |-------|if ($limit->start_date->lte($start) && $limit->end_date->lte($end)) {// return days in the range $start-$limit_end- return $start->diffInDays($limit->end_date) + 1; // add one day, the day itself+ return (int) $start->diffInDays($limit->end_date, true) + 1; // add one day, the day itself}// limit starts later and limit ends earlier// |-----------|// |-------|if ($limit->start_date->gte($start) && $limit->end_date->gte($end)) {// return days in the range $limit_start - $end- return $limit->start_date->diffInDays($end) + 1; // add one day, the day itself+ return (int) $limit->start_date->diffInDays($end, true) + 1; // add one day, the day itself}return 0;diff --git a/app/Repositories/Budget/OperationsRepository.php b/app/Repositories/Budget/OperationsRepository.phpindex b33ff50748..fdd59d4847 100644--- a/app/Repositories/Budget/OperationsRepository.php+++ b/app/Repositories/Budget/OperationsRepository.php@@ -51,7 +51,7 @@ class OperationsRepository implements OperationsRepositoryInterface$total = '0';$count = 0;foreach ($budget->budgetlimits as $limit) {- $diff = $limit->start_date->diffInDays($limit->end_date);+ $diff = (int) $limit->start_date->diffInDays($limit->end_date, true);$diff = 0 === $diff ? 1 : $diff;$amount = $limit->amount;$perDay = bcdiv($amount, (string)$diff);diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.phpindex 0e55fc4265..0e40eda652 100644--- a/app/Repositories/PiggyBank/PiggyBankRepository.php+++ b/app/Repositories/PiggyBank/PiggyBankRepository.php@@ -301,7 +301,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterfaceif (null !== $piggyBank->targetdate && $repetition->currentamount < $piggyBank->targetamount) {$now = today(config('app.timezone'));$startDate = null !== $piggyBank->startdate && $piggyBank->startdate->gte($now) ? $piggyBank->startdate : $now;- $diffInMonths = $startDate->diffInMonths($piggyBank->targetdate, false);+ $diffInMonths = (int) $startDate->diffInMonths($piggyBank->targetdate);$remainingAmount = bcsub($piggyBank->targetamount, $repetition->currentamount);// more than 1 month to go and still need money to save:diff --git a/app/Repositories/Recurring/RecurringRepository.php b/app/Repositories/Recurring/RecurringRepository.phpindex a22f2f6f3b..f915958e13 100644--- a/app/Repositories/Recurring/RecurringRepository.php+++ b/app/Repositories/Recurring/RecurringRepository.php@@ -476,7 +476,7 @@ class RecurringRepository implements RecurringRepositoryInterfaceif (false === $repDate) {$repDate = clone $today;}- $diffInYears = $today->diffInYears($repDate);+ $diffInYears = (int) $today->diffInYears($repDate, true);$repDate->addYears($diffInYears); // technically not necessary.$string = $repDate->isoFormat((string)trans('config.month_and_day_no_year_js'));diff --git a/app/Support/Chart/Category/WholePeriodChartGenerator.php b/app/Support/Chart/Category/WholePeriodChartGenerator.phpindex e1765dbfc9..3f9336e804 100644--- a/app/Support/Chart/Category/WholePeriodChartGenerator.php+++ b/app/Support/Chart/Category/WholePeriodChartGenerator.php@@ -113,7 +113,7 @@ class WholePeriodChartGeneratorprotected function calculateStep(Carbon $start, Carbon $end): string{$step = '1D';- $months = $start->diffInMonths($end);+ $months = $start->diffInMonths($end, true);if ($months > 3) {$step = '1W';}diff --git a/app/Support/Http/Controllers/DateCalculation.php b/app/Support/Http/Controllers/DateCalculation.phpindex ba1268e64a..e9ff23bb36 100644--- a/app/Support/Http/Controllers/DateCalculation.php+++ b/app/Support/Http/Controllers/DateCalculation.php@@ -39,7 +39,7 @@ trait DateCalculation*/public function activeDaysLeft(Carbon $start, Carbon $end): int{- $difference = $start->diffInDays($end) + 1;+ $difference = (int)($start->diffInDays($end, true) + 1);$today = today(config('app.timezone'))->startOfDay();if ($start->lte($today) && $end->gte($today)) {@@ -56,11 +56,11 @@ trait DateCalculation*/protected function activeDaysPassed(Carbon $start, Carbon $end): int{- $difference = $start->diffInDays($end) + 1;+ $difference = $start->diffInDays($end, true) + 1;$today = today(config('app.timezone'))->startOfDay();if ($start->lte($today) && $end->gte($today)) {- $difference = $start->diffInDays($today) + 1;+ $difference = $start->diffInDays($today, true) + 1;}return (int) $difference;@@ -69,7 +69,7 @@ trait DateCalculationprotected function calculateStep(Carbon $start, Carbon $end): string{$step = '1D';- $months = $start->diffInMonths($end);+ $months = $start->diffInMonths($end, true);if ($months > 3) {$step = '1W';}diff --git a/app/Support/Navigation.php b/app/Support/Navigation.phpindex c3dc065698..09c02e4c03 100644--- a/app/Support/Navigation.php+++ b/app/Support/Navigation.php@@ -252,7 +252,7 @@ class Navigation/** @var Carbon $tEnd */$tEnd = session('end', today(config('app.timezone'))->endOfMonth());- $diffInDays = $tStart->diffInDays($tEnd);+ $diffInDays = (int) $tStart->diffInDays($tEnd, true);}Log::debug(sprintf('Diff in days is %d', $diffInDays));$currentEnd->addDays($diffInDays);@@ -304,7 +304,7 @@ class Navigation{$endOfMonth = $date->copy()->endOfMonth();- return (int) $date->diffInDays($endOfMonth);+ return (int) $date->diffInDays($endOfMonth, true);}public function diffInPeriods(string $period, int $skip, Carbon $beginning, Carbon $end): int@@ -317,12 +317,12 @@ class Navigation$end->format('Y-m-d')));$map = [- 'daily' => 'floatDiffInDays',- 'weekly' => 'floatDiffInWeeks',- 'monthly' => 'floatDiffInMonths',- 'quarterly' => 'floatDiffInMonths',- 'half-year' => 'floatDiffInMonths',- 'yearly' => 'floatDiffInYears',+ 'daily' => 'diffInDays',+ 'weekly' => 'diffInWeeks',+ 'monthly' => 'diffInMonths',+ 'quarterly' => 'diffInMonths',+ 'half-year' => 'diffInMonths',+ 'yearly' => 'diffInYears',];if (!array_key_exists($period, $map)) {Log::warning(sprintf('No diffInPeriods for period "%s"', $period));@@ -331,7 +331,7 @@ class Navigation}$func = $map[$period];// first do the diff- $floatDiff = $beginning->{$func}($end); // @phpstan-ignore-line+ $floatDiff = $beginning->{$func}($end, true); // @phpstan-ignore-line// then correct for quarterly or half-yearif ('quarterly' === $period) {@@ -442,13 +442,13 @@ class Navigation$format = $this->preferredCarbonFormat($start, $end);$displayFormat = (string)trans('config.month_and_day_js', [], $locale);// increment by month (for year)- if ($start->diffInMonths($end) > 1) {+ if ($start->diffInMonths($end, true) > 1) {$increment = 'addMonth';$displayFormat = (string)trans('config.month_js');}- // increment by year (for multi year)- if ($start->diffInMonths($end) > 12) {+ // increment by year (for multi-year)+ if ($start->diffInMonths($end, true) > 12) {$increment = 'addYear';$displayFormat = (string)trans('config.year_js');}@@ -471,11 +471,11 @@ class Navigationpublic function preferredCarbonFormat(Carbon $start, Carbon $end): string{$format = 'Y-m-d';- if ($start->diffInMonths($end) > 1) {+ if ($start->diffInMonths($end, true) > 0) {$format = 'Y-m';}- if ($start->diffInMonths($end) > 12) {+ if ($start->diffInMonths($end, true) > 12) {$format = 'Y';}@@ -540,11 +540,11 @@ class Navigation{$locale = app('steam')->getLocale();$format = (string)trans('config.month_and_day_js', [], $locale);- if ($start->diffInMonths($end) > 1) {+ if ($start->diffInMonths($end, true) > 1) {$format = (string)trans('config.month_js', [], $locale);}- if ($start->diffInMonths($end) > 12) {+ if ($start->diffInMonths($end, true) > 12) {$format = (string)trans('config.year_js', [], $locale);}@@ -558,11 +558,11 @@ class Navigationpublic function preferredEndOfPeriod(Carbon $start, Carbon $end): string{$format = 'endOfDay';- if ($start->diffInMonths($end) > 1) {+ if ($start->diffInMonths($end, true) > 1) {$format = 'endOfMonth';}- if ($start->diffInMonths($end) > 12) {+ if ($start->diffInMonths($end, true) > 12) {$format = 'endOfYear';}@@ -576,11 +576,11 @@ class Navigationpublic function preferredRangeFormat(Carbon $start, Carbon $end): string{$format = '1D';- if ($start->diffInMonths($end) > 1) {+ if ($start->diffInMonths($end, true) > 1) {$format = '1M';}- if ($start->diffInMonths($end) > 12) {+ if ($start->diffInMonths($end, true) > 12) {$format = '1Y';}@@ -594,11 +594,11 @@ class Navigationpublic function preferredSqlFormat(Carbon $start, Carbon $end): string{$format = '%Y-%m-%d';- if ($start->diffInMonths($end) > 1) {+ if ($start->diffInMonths($end, true) > 1) {$format = '%Y-%m';}- if ($start->diffInMonths($end) > 12) {+ if ($start->diffInMonths($end, true) > 12) {$format = '%Y';}@@ -654,7 +654,7 @@ class Navigation/** @var Carbon $tEnd */$tEnd = session('end', today(config('app.timezone'))->endOfMonth());- $diffInDays = $tStart->diffInDays($tEnd);+ $diffInDays = (int) $tStart->diffInDays($tEnd, true);$date->subDays($diffInDays * $subtract);return $date;diff --git a/app/Transformers/V2/PiggyBankTransformer.php b/app/Transformers/V2/PiggyBankTransformer.phpindex 7b521de575..963ff01fee 100644--- a/app/Transformers/V2/PiggyBankTransformer.php+++ b/app/Transformers/V2/PiggyBankTransformer.php@@ -248,7 +248,7 @@ class PiggyBankTransformer extends AbstractTransformerif (bccomp($currentAmount, $targetAmount) < 1) {$now = today(config('app.timezone'));$startDate = null !== $startDate && $startDate->gte($now) ? $startDate : $now;- $diffInMonths = $startDate->diffInMonths($targetDate, false);+ $diffInMonths = (int) $startDate->diffInMonths($targetDate);$remainingAmount = bcsub($targetAmount, $currentAmount);// more than 1 month to go and still need money to save:diff --git a/tests/integration/Support/Models/BillDateCalculatorTest.php b/tests/integration/Support/Models/BillDateCalculatorTest.phpindex ae14f6b699..86a5ed8022 100644--- a/tests/integration/Support/Models/BillDateCalculatorTest.php+++ b/tests/integration/Support/Models/BillDateCalculatorTest.php@@ -48,7 +48,7 @@ final class BillDateCalculatorTest extends TestCase{// Carbon $earliest, Carbon $latest, Carbon $billStart, string $period, int $skip, ?Carbon $lastPaidreturn [- // basic monthly bill.+ // basic monthly bill.x'1Ma' => ['earliest' => Carbon::parse('2023-11-01'), 'latest' => Carbon::parse('2023-11-30'), 'billStart' => Carbon::parse('2023-01-01'), 'period' => 'monthly', 'skip' => 0, 'lastPaid' => null, 'expected' => ['2023-11-01']],// already paid on the first, expect it next month.'1Mb' => ['earliest' => Carbon::parse('2023-11-01'), 'latest' => Carbon::parse('2023-11-30'), 'billStart' => Carbon::parse('2023-01-01'), 'period' => 'monthly', 'skip' => 0, 'lastPaid' => Carbon::parse('2023-11-01'), 'expected' => ['2023-12-01']],