Fix to make sure that the index respects the fiscal year.

This commit is contained in:
James Cole
2018-12-31 13:44:24 +01:00
parent f80de95bb0
commit aeab5f0333
2 changed files with 28 additions and 3 deletions

View File

@@ -52,7 +52,7 @@ class FiscalHelper implements FiscalHelperInterface
*/
public function endOfFiscalYear(Carbon $date): Carbon
{
// get start of fiscal year for passed date
Log::debug(sprintf('Now in endOfFiscalYear(%s).', $date->format('Y-m-d')));
$endDate = $this->startOfFiscalYear($date);
if (true === $this->useCustomFiscalYear) {
// add 1 year and sub 1 day
@@ -62,6 +62,7 @@ class FiscalHelper implements FiscalHelperInterface
if (false === $this->useCustomFiscalYear) {
$endDate->endOfYear();
}
Log::debug(sprintf('Result of endOfFiscalYear(%s) = %s', $date->format('Y-m-d'), $endDate->format('Y-m-d')));
return $endDate;
}
@@ -73,6 +74,12 @@ class FiscalHelper implements FiscalHelperInterface
*/
public function startOfFiscalYear(Carbon $date): Carbon
{
// because PHP is stupid:
if ($date->day >= 28) {
$date->day = 28;
Log::info(sprintf('Corrected date to %s', $date->format('Y-m-d')));
}
// get start mm-dd. Then create a start date in the year passed.
$startDate = clone $date;
if (true === $this->useCustomFiscalYear) {
@@ -89,6 +96,8 @@ class FiscalHelper implements FiscalHelperInterface
$startDate->startOfYear();
}
Log::debug(sprintf('Result of startOfFiscalYear(%s) = %s', $date->format('Y-m-d'), $startDate->format('Y-m-d')));
return $startDate;
}
}