Skip to content

Commit

Permalink
Better call to date.
Browse files Browse the repository at this point in the history
  • Loading branch information
JC5 committed Sep 11, 2020
1 parent 0b308cb commit 284222c
Show file tree
Hide file tree
Showing 33 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion app/Api/V1/Controllers/SummaryController.php
Expand Up @@ -328,7 +328,7 @@ private function getBillInformation(Carbon $start, Carbon $end): array
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);
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Export/ExportData.php
Expand Up @@ -230,7 +230,7 @@ private function getDateParameter(string $field): Carbon
return $date;
}
if ('end' === $field) {
$date = new Carbon;
$date = today(config('app.timezone'));
$date->endOfDay();

return $date;
Expand Down
2 changes: 1 addition & 1 deletion app/Factory/TransactionJournalFactory.php
Expand Up @@ -258,7 +258,7 @@ private function createJournal(NullArrayObject $row): ?TransactionJournal

/** 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']);
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Account/ShowController.php
Expand Up @@ -106,7 +106,7 @@ public function show(Request $request, Account $account, Carbon $start = null, C
}
$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;
Expand Down Expand Up @@ -173,8 +173,8 @@ public function showAll(Request $request, Account $account)
$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');
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/TelemetryController.php
Expand Up @@ -87,7 +87,7 @@ public function deleteAll()
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'));
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Category/NoCategoryController.php
Expand Up @@ -126,7 +126,7 @@ public function showAll(Request $request)
$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')));

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Category/ShowController.php
Expand Up @@ -129,8 +129,8 @@ public function showAll(Request $request, Category $category)
$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);

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Chart/CategoryController.php
Expand Up @@ -230,7 +230,7 @@ private function getDate(): Carbon
{
$carbon = null;
try {
$carbon = new Carbon;
$carbon = today(config('app.timezone'));
} catch (Exception $e) {
$e->getMessage();
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Chart/PiggyBankController.php
Expand Up @@ -79,15 +79,15 @@ public function history(PiggyBankRepositoryInterface $repository, PiggyBank $pig
$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();
$firstDate = null === $firstEvent ? new Carbon : $firstEvent->date;

// 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);

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Export/IndexController.php
Expand Up @@ -79,7 +79,7 @@ public function export(): LaravelResponse
$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) {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/HomeController.php
Expand Up @@ -126,7 +126,7 @@ public function index(AccountRepositoryInterface $repository)
$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);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Json/BoxController.php
Expand Up @@ -68,7 +68,7 @@ public function available(): JsonResponse
$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');

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/PiggyBank/AmountController.php
Expand Up @@ -76,7 +76,7 @@ function ($request, $next) {
*/
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);
Expand All @@ -95,7 +95,7 @@ public function add(PiggyBank $piggyBank)
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);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/PiggyBank/CreateController.php
Expand Up @@ -96,7 +96,7 @@ public function store(PiggyBankStoreRequest $request)
{
$data = $request->getPiggyBankData();
if (null === $data['startdate']) {
$data['startdate'] = new Carbon;
$data['startdate'] = today(config('app.timezone'));
}
$piggyBank = $this->piggyRepos->store($data);

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Recurring/CreateController.php
Expand Up @@ -85,7 +85,7 @@ public function createFromJournal(Request $request, TransactionJournal $journal)
{
$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();

Expand Down Expand Up @@ -179,7 +179,7 @@ public function create(Request $request)
{
$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();

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Recurring/IndexController.php
Expand Up @@ -85,8 +85,8 @@ public function index(Request $request)
$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();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Recurring/ShowController.php
Expand Up @@ -84,7 +84,7 @@ public function show(Recurrence $recurrence)

$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:
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ReportController.php
Expand Up @@ -263,7 +263,7 @@ public function doubleReport(Collection $accounts, Collection $expense, Carbon $
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(
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/TagController.php
Expand Up @@ -251,7 +251,7 @@ public function show(Request $request, Tag $tag, Carbon $start = null, Carbon $e
);

$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')]);
Expand Down Expand Up @@ -285,8 +285,8 @@ public function showAll(Request $request, Tag $tag)
$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);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Transaction/IndexController.php
Expand Up @@ -144,7 +144,7 @@ public function indexAll(Request $request, string $objectType)
$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 */
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/RecurrenceFormRequest.php
Expand Up @@ -144,7 +144,7 @@ public function getAll(): array
*/
public function rules(): array
{
$today = new Carbon;
$today = today(config('app.timezone'));
$tomorrow = Carbon::now()->addDay();
$rules = [
// mandatory info for recurrence.
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Requests/ReportFormRequest.php
Expand Up @@ -151,7 +151,7 @@ public function getDoubleList(): Collection
*/
public function getEndDate(): Carbon
{
$date = new Carbon;
$date = today(config('app.timezone'));
$range = $this->get('daterange');
$parts = explode(' - ', (string) $range);
if (2 === count($parts)) {
Expand Down Expand Up @@ -179,7 +179,7 @@ public function getEndDate(): Carbon
*/
public function getStartDate(): Carbon
{
$date = new Carbon;
$date = today(config('app.timezone'));
$range = $this->get('daterange');
$parts = explode(' - ', (string) $range);
if (2 === count($parts)) {
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/SubmitTelemetryData.php
Expand Up @@ -151,7 +151,7 @@ private function markAsSubmitted(Collection $telemetry): void
{
$telemetry->each(
static function (Telemetry $entry) {
$entry->submitted = new Carbon;
$entry->submitted = today(config('app.timezone'));
$entry->save();
}
);
Expand Down
2 changes: 1 addition & 1 deletion app/Repositories/Budget/BudgetRepository.php
Expand Up @@ -307,7 +307,7 @@ public function store(array $data): Budget
$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);

Expand Down
2 changes: 1 addition & 1 deletion app/Repositories/PiggyBank/ModifiesPiggyBanks.php
Expand Up @@ -101,7 +101,7 @@ public function addAmountToRepetition(PiggyBankRepetition $repetition, string $a
*/
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));
Expand Down
4 changes: 2 additions & 2 deletions app/Services/Currency/FixerIOv2.php
Expand Up @@ -67,8 +67,8 @@ public function getRate(TransactionCurrency $fromCurrency, TransactionCurrency $
$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');
Expand Down
4 changes: 2 additions & 2 deletions app/Services/Currency/RatesApiIOv1.php
Expand Up @@ -67,8 +67,8 @@ public function getRate(TransactionCurrency $fromCurrency, TransactionCurrency $
$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(
Expand Down
2 changes: 1 addition & 1 deletion app/Support/Cronjobs/AbstractCronjob.php
Expand Up @@ -49,7 +49,7 @@ abstract class AbstractCronjob
public function __construct()
{
$this->force = false;
$this->date = new Carbon;
$this->date = today(config('app.timezone'));
}


Expand Down
4 changes: 2 additions & 2 deletions app/Support/Export/ExportDataGenerator.php
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/Support/Form/FormSupport.php
Expand Up @@ -54,7 +54,7 @@ protected function getDate(): Carbon
/** @var Carbon $date */
$date = null;
try {
$date = new Carbon;
$date = today(config('app.timezone'));
} catch (Exception $e) {
$e->getMessage();
}
Expand Down
2 changes: 1 addition & 1 deletion app/Support/Http/Controllers/GetConfigurationData.php
Expand Up @@ -101,7 +101,7 @@ protected function getDateRangeConfig(): array // get configuration + get prefer
$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],
Expand Down
2 changes: 1 addition & 1 deletion app/Support/Http/Controllers/PeriodOverview.php
Expand Up @@ -288,7 +288,7 @@ protected function getNoCategoryPeriodOverview(Carbon $theDate): array
$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')));
Expand Down
2 changes: 1 addition & 1 deletion app/Support/Twig/TransactionGroupTwig.php
Expand Up @@ -71,7 +71,7 @@ static function (int $journalId, string $metaField) {
->whereNull('deleted_at')
->first();
if (null === $entry) {
return new Carbon;
return today(config('app.timezone'));
}

return new Carbon(json_decode($entry->data, false));
Expand Down

0 comments on commit 284222c

Please sign in to comment.