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

@@ -328,7 +328,7 @@ class SummaryController extends Controller
private function getLeftToSpendInfo(Carbon $start, Carbon $end): array
{
$return = [];
$today = new Carbon;
$today = today(config('app.timezone'));
$available = $this->abRepository->getAvailableBudgetWithCurrency($start, $end);
$budgets = $this->budgetRepository->getActiveBudgets();
$spent = $this->opsRepository->sumExpenses($start, $end, null, $budgets);

View File

@@ -230,7 +230,7 @@ class ExportData extends Command
return $date;
}
if ('end' === $field) {
$date = new Carbon;
$date = today(config('app.timezone'));
$date->endOfDay();
return $date;

View File

@@ -258,7 +258,7 @@ class TransactionJournalFactory
/** Some basic fields */
$type = $this->typeRepository->findTransactionType(null, $row['type']);
$carbon = $row['date'] ?? new Carbon;
$carbon = $row['date'] ?? today(config('app.timezone'));
$order = $row['order'] ?? 0;
$currency = $this->currencyRepository->findCurrency((int) $row['currency_id'], $row['currency_code']);
$foreignCurrency = $this->currencyRepository->findCurrencyNull($row['foreign_currency_id'], $row['foreign_currency_code']);

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 */

View File

@@ -144,7 +144,7 @@ class RecurrenceFormRequest extends FormRequest
*/
public function rules(): array
{
$today = new Carbon;
$today = today(config('app.timezone'));
$tomorrow = Carbon::now()->addDay();
$rules = [
// mandatory info for recurrence.

View File

@@ -151,7 +151,7 @@ class ReportFormRequest extends FormRequest
*/
public function getEndDate(): Carbon
{
$date = new Carbon;
$date = today(config('app.timezone'));
$range = $this->get('daterange');
$parts = explode(' - ', (string) $range);
if (2 === count($parts)) {
@@ -179,7 +179,7 @@ class ReportFormRequest extends FormRequest
*/
public function getStartDate(): Carbon
{
$date = new Carbon;
$date = today(config('app.timezone'));
$range = $this->get('daterange');
$parts = explode(' - ', (string) $range);
if (2 === count($parts)) {

View File

@@ -151,7 +151,7 @@ class SubmitTelemetryData implements ShouldQueue
{
$telemetry->each(
static function (Telemetry $entry) {
$entry->submitted = new Carbon;
$entry->submitted = today(config('app.timezone'));
$entry->save();
}
);

View File

@@ -307,7 +307,7 @@ class BudgetRepository implements BudgetRepositoryInterface
$autoBudget->save();
// create initial budget limit.
$today = new Carbon;
$today = today(config('app.timezone'));
$start = app('navigation')->startOfPeriod($today, $autoBudget->period);
$end = app('navigation')->endOfPeriod($start, $autoBudget->period);

View File

@@ -101,7 +101,7 @@ trait ModifiesPiggyBanks
*/
public function canAddAmount(PiggyBank $piggyBank, string $amount): bool
{
$leftOnAccount = $this->leftOnAccount($piggyBank, new Carbon);
$leftOnAccount = $this->leftOnAccount($piggyBank, today(config('app.timezone')));
$savedSoFar = (string) $this->getRepetition($piggyBank)->currentamount;
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
$maxAmount = (string) min(round($leftOnAccount, 12), round($leftToSave, 12));

View File

@@ -67,8 +67,8 @@ class FixerIOv2 implements ExchangeRateInterface
$exchangeRate->toCurrency()->associate($toCurrency);
$exchangeRate->date = $date;
$exchangeRate->rate = $rate;
$exchangeRate->updated_at = new Carbon;
$exchangeRate->created_at = new Carbon;
$exchangeRate->updated_at = today(config('app.timezone'));
$exchangeRate->created_at = today(config('app.timezone'));
// get API key
$apiKey = config('firefly.fixer_api_key');

View File

@@ -67,8 +67,8 @@ class RatesApiIOv1 implements ExchangeRateInterface
$exchangeRate->toCurrency()->associate($toCurrency);
$exchangeRate->date = $date;
$exchangeRate->rate = $rate;
$exchangeRate->updated_at = new Carbon;
$exchangeRate->created_at = new Carbon;
$exchangeRate->updated_at = today(config('app.timezone'));
$exchangeRate->created_at = today(config('app.timezone'));
// build URI
$uri = sprintf(

View File

@@ -49,7 +49,7 @@ abstract class AbstractCronjob
public function __construct()
{
$this->force = false;
$this->date = new Carbon;
$this->date = today(config('app.timezone'));
}

View File

@@ -84,9 +84,9 @@ class ExportDataGenerator
public function __construct()
{
$this->start = new Carbon;
$this->start = today(config('app.timezone'));
$this->start->subYear();
$this->end = new Carbon;
$this->end = today(config('app.timezone'));
$this->exportTransactions = false;
$this->exportAccounts = false;
$this->exportBudgets = false;

View File

@@ -54,7 +54,7 @@ trait FormSupport
/** @var Carbon $date */
$date = null;
try {
$date = new Carbon;
$date = today(config('app.timezone'));
} catch (Exception $e) {
$e->getMessage();
}

View File

@@ -101,7 +101,7 @@ trait GetConfigurationData
$first = session('first');
$title = sprintf('%s - %s', $start->formatLocalized($this->monthAndDayFormat), $end->formatLocalized($this->monthAndDayFormat));
$isCustom = true === session('is_custom_range', false);
$today = new Carbon;
$today = today(config('app.timezone'));
$ranges = [
// first range is the current range:
$title => [$start, $end],

View File

@@ -288,7 +288,7 @@ trait PeriodOverview
$range = app('preferences')->get('viewRange', '1M')->data;
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon : $first->date;
$end = $theDate ?? new Carbon;
$end = $theDate ?? today(config('app.timezone'));
Log::debug(sprintf('Start for getNoCategoryPeriodOverview() is %s', $start->format('Y-m-d')));
Log::debug(sprintf('End for getNoCategoryPeriodOverview() is %s', $end->format('Y-m-d')));

View File

@@ -71,7 +71,7 @@ class TransactionGroupTwig extends AbstractExtension
->whereNull('deleted_at')
->first();
if (null === $entry) {
return new Carbon;
return today(config('app.timezone'));
}
return new Carbon(json_decode($entry->data, false));