aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYaroslav <contact@yaroslavps.com>2020-10-06 14:13:14 +0300
committerYaroslav <contact@yaroslavps.com>2020-10-06 14:13:14 +0300
commit742b9fa46d74762f58ae939afd980a532cc4636f (patch)
tree0cd372442e5518dece1a9ec371ae71dccc5faae4 /src
parentcc688c4dc73d3b13be5aba1bd292cc31265c5d04 (diff)
downloadfinbudg-0.1.2.tar.gz
finbudg-0.1.2.zip
Account for days elapsed based on latest datev0.1.2
Instead of counting the number of days for the averge through the number of iterations, let it be the difference between the latest date on entry and the start of the period. Id est: * 'Missing' dates from the input are implicit. * The order of the days doesn't affect the output (although it doesn't make sense to put the days out of order).
Diffstat (limited to 'src')
-rw-r--r--src/main.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index 04d5277..5c64959 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -33,7 +33,7 @@ fn main() {
::std::process::exit(1);
}
};
- let calculated = budget::calculate(&account);
+ let maybe_calculated = budget::calculate(&account);
if no_color && !force_color {
colored::control::set_override(false);
@@ -41,7 +41,7 @@ fn main() {
colored::control::set_override(true);
}
- output(account, calculated);
+ output(account, maybe_calculated);
}
fn get_cli_matches() -> ArgMatches<'static> {
@@ -68,7 +68,7 @@ fn get_cli_matches() -> ArgMatches<'static> {
.get_matches()
}
-fn output(account: Account, calculated: Calculated) {
+fn output(account: Account, maybe_calculated: Option<Calculated>) {
println!(
"{}",
format!(
@@ -78,22 +78,23 @@ fn output(account: Account, calculated: Calculated) {
).cyan(),
);
- let last_day = match account.days.last() {
- Some(day) => day,
+ let calculated = match maybe_calculated {
+ Some(data) => data,
None => {
- println!("{}", "Your expenses are empty...".italic());
+ println!();
+ println!("{}", "You have no expenses...".italic());
::std::process::exit(0);
}
};
- let days_until_end = account.end_date - last_day.date;
+ let days_until_end = account.end_date - calculated.last_day;
println!(
"{}",
format!(
"Last day on entry: {}",
- last_day.date.format("%Y-%m-%d"),
+ calculated.last_day.format("%Y-%m-%d"),
).cyan(),
);