From 7918c89cac4a84f21768e7c71b2a71a423078128 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Mon, 9 Oct 2023 20:33:43 +0200 Subject: [PATCH] Minor cleanups --- src/overview.cpp | 7 ++----- src/share.cpp | 11 ++++------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/overview.cpp b/src/overview.cpp index 539c94d..ac25ec8 100644 --- a/src/overview.cpp +++ b/src/overview.cpp @@ -491,9 +491,7 @@ budget::month get_current_months(data_cache & cache, budget::year year){ auto sm = start_month(cache, year); budget::month current_months = budget::month(12) - sm + budget::month(1); - auto today = budget::local_day(); - - if(today.year() == year){ + if(auto today = budget::local_day(); today.year() == year){ current_months = today.month() - sm + date_type(1); } @@ -1008,8 +1006,7 @@ void budget::display_balance(budget::writer& w, budget::year year, bool relaxed, auto today = budget::local_day(); if(year > today.year()){ auto pretotal = compute_total_budget(w.cache, sm, year); - size_t i = 0; - for(const auto& account : all_accounts(w.cache, year, sm)){ + for(size_t i = 0; const auto& account : all_accounts(w.cache, year, sm)){ account_previous[account.name][sm.value - 1] += pretotal[i++] - account.amount; } } diff --git a/src/share.cpp b/src/share.cpp index b78b3ce..8c867d9 100644 --- a/src/share.cpp +++ b/src/share.cpp @@ -54,20 +54,17 @@ budget::date get_valid_date(const budget::date & d){ if (d >= budget::local_day()) { auto now = std::chrono::system_clock::now(); auto tt = std::chrono::system_clock::to_time_t(now); - auto tm = *std::localtime(&tt); // We make sure that we are on a new U.S: day // TODO This should be done by getting the current time in the U.S. - if (tm.tm_hour > 15) { + if (auto tm = *std::localtime(&tt); tm.tm_hour > 15) { return get_valid_date(budget::local_day() - budget::days(1)); } return get_valid_date(budget::local_day() - budget::days(2)); } - auto dow = d.day_of_the_week(); - - if (dow == 6 || dow == 7){ + if (auto dow = d.day_of_the_week(); dow == 6 || dow == 7){ return get_valid_date(d - budget::days(dow - 5)); } @@ -149,9 +146,9 @@ std::map> get_share_price_v3(c const share_price_cache_key key(d, ticker); quotes[key] = m; } - } catch (const budget::date_exception& e) { + } catch (const budget::date_exception&) { return {}; - } catch (const budget::budget_exception& e) { + } catch (const budget::budget_exception&) { return {}; }