diff options
author | Akshay <nerdypepper@tuta.io> | 2020-02-27 18:23:19 +0530 |
---|---|---|
committer | Akshay <nerdypepper@tuta.io> | 2020-02-27 18:23:19 +0530 |
commit | cc8cde9b229b1cd8de8e9e67b164c80b1cdc0ebf (patch) | |
tree | 438de2cdd2edb48f62951175ae3d90602fe9ff8b | |
parent | 16a01454c2340c8f631f17277647737aeb5e3049 (diff) |
add helpers for statusline
-rw-r--r-- | src/habit.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/habit.rs b/src/habit.rs index 8527ac2..7d50adf 100644 --- a/src/habit.rs +++ b/src/habit.rs @@ -34,6 +34,7 @@ pub trait HabitTrait { fn insert_entry(&mut self, date: NaiveDate, val: HabitType); fn reached_goal(&self, date: NaiveDate) -> bool; fn remaining(&self, date: NaiveDate) -> u32; + fn total(&self) -> u32; } #[derive(Serialize, Debug)] @@ -75,7 +76,7 @@ impl Habit { } else { match self.goal { HabitType::Bit(_) => self.insert_entry(date, HabitType::Bit(true)), - HabitType::Count(_) => self.insert_entry(date, HabitType::Count(0)), + HabitType::Count(_) => self.insert_entry(date, HabitType::Count(1)), } } } @@ -119,7 +120,13 @@ impl HabitTrait for Habit { HabitType::Count(c) => return self.goal.inner_count() - *c, } } else { - return 0; + return self.total(); + } + } + fn total(&self) -> u32 { + match self.goal { + HabitType::Bit(_) => return 1, + HabitType::Count(c) => return c, } } } |