2016-01-09 08:39:34 -06:00
|
|
|
<?php
|
2016-02-05 05:08:25 -06:00
|
|
|
declare(strict_types = 1);
|
2016-01-09 08:39:34 -06:00
|
|
|
/**
|
|
|
|
* Date.php
|
2016-04-01 09:44:46 -05:00
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
2016-01-09 08:39:34 -06:00
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace FireflyIII\Support\Binder;
|
|
|
|
|
2016-01-15 10:38:09 -06:00
|
|
|
use Auth;
|
2016-01-09 08:39:34 -06:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use Exception;
|
2016-02-04 00:28:39 -06:00
|
|
|
use FireflyIII\Helpers\FiscalHelper;
|
2016-01-09 08:39:34 -06:00
|
|
|
use Log;
|
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Date
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Support\Binder
|
|
|
|
*/
|
|
|
|
class Date implements BinderInterface
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
* @param $route
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-02-06 03:11:06 -06:00
|
|
|
public static function routeBinder($value, $route): Carbon
|
2016-01-09 08:39:34 -06:00
|
|
|
{
|
2016-01-28 17:11:36 -06:00
|
|
|
$fiscalHelper = new FiscalHelper;
|
|
|
|
|
2016-01-22 03:10:51 -06:00
|
|
|
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();
|
2016-01-28 17:11:36 -06:00
|
|
|
case 'currentFiscalYearStart':
|
|
|
|
return $fiscalHelper->startOfFiscalYear(Carbon::now());
|
|
|
|
case 'currentFiscalYearEnd':
|
|
|
|
return $fiscalHelper->endOfFiscalYear(Carbon::now());
|
2016-01-22 00:54:15 -06:00
|
|
|
|
2016-01-09 08:39:34 -06:00
|
|
|
}
|
|
|
|
}
|
2016-01-22 00:54:15 -06:00
|
|
|
}
|