Skip to content

Commit a3a24ae

Browse files
committed
Avoid computations in the future
1 parent 5c30bb0 commit a3a24ae

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/overview.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,24 +1151,28 @@ void budget::display_month_overview(budget::month month, budget::year year, budg
11511151

11521152
const budget::date today = budget::local_day();
11531153
const budget::date month_start(year, month, 1);
1154-
budget::date month_end = month_start.end_of_month();
11551154

1156-
// If we are on the current month, we avoid going into the future
1157-
if (month_start.year() == today.year() && month_start.month() == today.month()) {
1158-
month_end = today;
1159-
}
1155+
// We cannot compute NW increases in the future
1156+
if (month_start.end_of_month() < today) {
1157+
budget::date month_end = month_start.end_of_month();
11601158

1161-
auto net_worth_end = get_net_worth(month_end, writer.cache);
1162-
auto net_worth_month_start = get_net_worth(month_start, writer.cache);
1159+
// If we are on the current month, we avoid going into the future
1160+
if (month_start.year() == today.year() && month_start.month() == today.month()) {
1161+
month_end = today;
1162+
}
11631163

1164-
auto month_increase = net_worth_end - net_worth_month_start;
1164+
auto net_worth_end = get_net_worth(month_end, writer.cache);
1165+
auto net_worth_month_start = get_net_worth(month_start, writer.cache);
11651166

1166-
second_contents.emplace_back(std::vector<std::string>{"Net Worth Increase", budget::to_string(month_increase)});
1167+
auto month_increase = net_worth_end - net_worth_month_start;
11671168

1168-
if (month_increase.zero() || month_increase.negative()) {
1169-
second_contents.emplace_back(std::vector<std::string>{"Savings Contribution", "N/A"});
1170-
} else {
1171-
second_contents.emplace_back(std::vector<std::string>{"Savings Contribution", budget::to_string(100.0 * (savings / month_increase)) + "%"});
1169+
second_contents.emplace_back(std::vector<std::string>{"Net Worth Increase", budget::to_string(month_increase)});
1170+
1171+
if (month_increase.zero() || month_increase.negative()) {
1172+
second_contents.emplace_back(std::vector<std::string>{"Savings Contribution", "N/A"});
1173+
} else {
1174+
second_contents.emplace_back(std::vector<std::string>{"Savings Contribution", budget::to_string(100.0 * (savings / month_increase)) + "%"});
1175+
}
11721176
}
11731177

11741178
writer.display_table(second_columns, second_contents, 1, {}, accounts.size() * 9 + 1);

0 commit comments

Comments
 (0)