Better call to date.

This commit is contained in:
James Cole
2020-09-11 07:12:33 +02:00
parent 0b308cb5f2
commit 284222c2ee
33 changed files with 46 additions and 46 deletions

View File

@@ -106,7 +106,7 @@ class ShowController extends Controller
}
$location = $this->repository->getLocation($account);
$attachments = $this->repository->getAttachments($account);
$today = new Carbon;
$today = today(config('app.timezone'));
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
@@ -173,8 +173,8 @@ class ShowController extends Controller
$isLiability = $this->repository->isLiability($account);
$attachments = $this->repository->getAttachments($account);
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
$end = new Carbon;
$today = new Carbon;
$end = today(config('app.timezone'));
$today = today(config('app.timezone'));
$start = $this->repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
$page = (int) $request->get('page');

View File

@@ -87,7 +87,7 @@ class TelemetryController extends Controller
public function submit()
{
$job = app(SubmitTelemetryData::class);
$job->setDate(new Carbon);
$job->setDate(today(config('app.timezone')));
$job->setForce(true);
$job->handle();
session()->flash('info', trans('firefly.telemetry_submission_executed'));

View File

@@ -126,7 +126,7 @@ class NoCategoryController extends Controller
$subTitle = (string) trans('firefly.all_journals_without_category');
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon : $first->date;
$end = new Carbon;
$end = today(config('app.timezone'));
Log::debug(sprintf('Start for noCategory() is %s', $start->format('Y-m-d')));
Log::debug(sprintf('End for noCategory() is %s', $end->format('Y-m-d')));

View File

@@ -129,8 +129,8 @@ class ShowController extends Controller
$subTitle = (string) trans('firefly.all_journals_for_category', ['name' => $category->name]);
$first = $this->repository->firstUseDate($category);
/** @var Carbon $start */
$start = $first ?? new Carbon;
$end = new Carbon;
$start = $first ?? today(config('app.timezone'));
$end = today(config('app.timezone'));
$path = route('categories.show.all', [$category->id]);
$attachments = $this->repository->getAttachments($category);

View File

@@ -230,7 +230,7 @@ class CategoryController extends Controller
{
$carbon = null;
try {
$carbon = new Carbon;
$carbon = today(config('app.timezone'));
} catch (Exception $e) {
$e->getMessage();
}

View File

@@ -79,7 +79,7 @@ class PiggyBankController extends Controller
$locale =app('steam')->getLocale();
// get first event or start date of piggy bank or today
$startDate = $piggyBank->start_date ?? new Carbon;
$startDate = $piggyBank->start_date ?? today(config('app.timezone'));
/** @var PiggyBankEvent $first */
$firstEvent = $set->first();
@@ -87,7 +87,7 @@ class PiggyBankController extends Controller
// which ever is older:
$oldest = $startDate->lt($firstDate) ? $startDate : $firstDate;
$today = new Carbon;
$today = today(config('app.timezone'));
// depending on diff, do something with range of chart.
$step = $this->calculateStep($oldest, $today);

View File

@@ -79,7 +79,7 @@ class IndexController extends Controller
$generator->setExportTransactions(true);
// get first transaction in DB:
$firstDate = new Carbon;
$firstDate = today(config('app.timezone'));
$firstDate->subYear();
$journal = $this->journalRepository->firstNull();
if (null !== $journal) {

View File

@@ -126,7 +126,7 @@ class HomeController extends Controller
$end = session('end', Carbon::now()->endOfMonth());
/** @noinspection NullPointerExceptionInspection */
$accounts = $repository->getAccountsById($frontPage->data);
$today = new Carbon;
$today = today(config('app.timezone'));
/** @var BillRepositoryInterface $billRepository */
$billRepository = app(BillRepositoryInterface::class);

View File

@@ -68,7 +68,7 @@ class BoxController extends Controller
$start = session('start', Carbon::now()->startOfMonth());
/** @var Carbon $end */
$end = session('end', Carbon::now()->endOfMonth());
$today = new Carbon;
$today = today(config('app.timezone'));
$display = 2; // see method docs.
$boxTitle = (string) trans('firefly.spent');

View File

@@ -76,7 +76,7 @@ class AmountController extends Controller
*/
public function add(PiggyBank $piggyBank)
{
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, new Carbon);
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, today(config('app.timezone')));
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
$maxAmount = min($leftOnAccount, $leftToSave);
@@ -95,7 +95,7 @@ class AmountController extends Controller
public function addMobile(PiggyBank $piggyBank)
{
/** @var Carbon $date */
$date = session('end', new Carbon);
$date = session('end', today(config('app.timezone')));
$leftOnAccount = $this->piggyRepos->leftOnAccount($piggyBank, $date);
$savedSoFar = $this->piggyRepos->getCurrentAmount($piggyBank);
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);

View File

@@ -96,7 +96,7 @@ class CreateController extends Controller
{
$data = $request->getPiggyBankData();
if (null === $data['startdate']) {
$data['startdate'] = new Carbon;
$data['startdate'] = today(config('app.timezone'));
}
$piggyBank = $this->piggyRepos->store($data);

View File

@@ -85,7 +85,7 @@ class CreateController extends Controller
{
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
$defaultCurrency = app('amount')->getDefaultCurrency();
$tomorrow = new Carbon;
$tomorrow = today(config('app.timezone'));
$oldRepetitionType = $request->old('repetition_type');
$tomorrow->addDay();
@@ -179,7 +179,7 @@ class CreateController extends Controller
{
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
$defaultCurrency = app('amount')->getDefaultCurrency();
$tomorrow = new Carbon;
$tomorrow = today(config('app.timezone'));
$oldRepetitionType = $request->old('repetition_type');
$tomorrow->addDay();

View File

@@ -85,8 +85,8 @@ class IndexController extends Controller
$page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$collection = $this->recurring->get();
$today = new Carbon;
$year = new Carbon;
$today = today(config('app.timezone'));
$year = today(config('app.timezone'));
// split collection
$total = $collection->count();

View File

@@ -84,7 +84,7 @@ class ShowController extends Controller
$array = $transformer->transform($recurrence);
$groups = $this->recurring->getTransactions($recurrence);
$today = new Carbon;
$today = today(config('app.timezone'));
$array['repeat_until'] = null !== $array['repeat_until'] ? new Carbon($array['repeat_until']) : null;
// transform dates back to Carbon objects:

View File

@@ -263,7 +263,7 @@ class ReportController extends Controller
public function index(AccountRepositoryInterface $repository)
{
/** @var Carbon $start */
$start = clone session('first', new Carbon);
$start = clone session('first', today(config('app.timezone')));
$months = $this->helper->listOfMonths($start);
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
$accounts = $repository->getAccountsByType(

View File

@@ -251,7 +251,7 @@ class TagController extends Controller
);
$startPeriod = $this->repository->firstUseDate($tag);
$startPeriod = $startPeriod ?? new Carbon;
$startPeriod = $startPeriod ?? today(config('app.timezone'));
$endPeriod = clone $end;
$periods = $this->getTagPeriodOverview($tag, $startPeriod, $endPeriod);
$path = route('tags.show', [$tag->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
@@ -285,8 +285,8 @@ class TagController extends Controller
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$periods = [];
$subTitle = (string) trans('firefly.all_journals_for_tag', ['tag' => $tag->tag]);
$start = $this->repository->firstUseDate($tag) ?? new Carbon;
$end = $this->repository->lastUseDate($tag) ?? new Carbon;
$start = $this->repository->firstUseDate($tag) ?? today(config('app.timezone'));
$end = $this->repository->lastUseDate($tag) ?? today(config('app.timezone'));
$attachments = $this->repository->getAttachments($tag);
$path = route('tags.show', [$tag->id, 'all']);
$location = $this->repository->getLocation($tag);

View File

@@ -144,7 +144,7 @@ class IndexController extends Controller
$first = $repository->firstNull();
$start = null === $first ? new Carbon : $first->date;
$last = $this->repository->getLast();
$end = $last ? $last->date : new Carbon;
$end = $last ? $last->date : today(config('app.timezone'));
$subTitle = (string) trans('firefly.all_' . $objectType);
/** @var GroupCollectorInterface $collector */