aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
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/main.rs
parentcc688c4dc73d3b13be5aba1bd292cc31265c5d04 (diff)
downloadfinbudg-370dc39882eebda85fa239a976e2fce19b819dbb.tar.gz
finbudg-370dc39882eebda85fa239a976e2fce19b819dbb.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/main.rs')
-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(),
);