. */ declare(strict_types=1); namespace FireflyIII\Support\Binder; use Carbon\Carbon; use Exception; use FireflyIII\Helpers\FiscalHelperInterface; use Illuminate\Routing\Route; use Log; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Class Date. */ class Date implements BinderInterface { /** * @param string $value * @param Route $route * * @return Carbon */ public static function routeBinder(string $value, Route $route): Carbon { /** @var FiscalHelperInterface $fiscalHelper */ $fiscalHelper = app(FiscalHelperInterface::class); switch ($value) { default: try { $date = new Carbon($value); } catch (Exception $e) { Log::error('Could not parse date "' . $value . '" for user #' . auth()->user()->id); throw new NotFoundHttpException; } return $date; case 'currentMonthStart': return Carbon::now()->startOfMonth(); case 'currentMonthEnd': return Carbon::now()->endOfMonth(); case 'currentYearStart': return Carbon::now()->startOfYear(); case 'currentYearEnd': return Carbon::now()->endOfYear(); case 'currentFiscalYearStart': return $fiscalHelper->startOfFiscalYear(Carbon::now()); case 'currentFiscalYearEnd': return $fiscalHelper->endOfFiscalYear(Carbon::now()); } } }