diff options
author | Akshay <[email protected]> | 2020-07-20 16:43:45 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-07-20 16:43:45 +0100 |
commit | 2a3be003015bac9c6a13549029b9fb4595e88384 (patch) | |
tree | 6d613a1b59ca277a82c8a688ec029774d10f31d5 /src/habit/bit.rs | |
parent | 8b91a7c0b3d9bd4fac3b140f5bc8a40ac324289a (diff) |
allow "untracking" of habits, closes #18
Diffstat (limited to 'src/habit/bit.rs')
-rw-r--r-- | src/habit/bit.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/habit/bit.rs b/src/habit/bit.rs index 3386182..8fa14c2 100644 --- a/src/habit/bit.rs +++ b/src/habit/bit.rs | |||
@@ -100,11 +100,22 @@ impl Habit for Bit { | |||
100 | fn goal(&self) -> u32 { | 100 | fn goal(&self) -> u32 { |
101 | return 1; | 101 | return 1; |
102 | } | 102 | } |
103 | fn modify(&mut self, date: NaiveDate, _: TrackEvent) { | 103 | fn modify(&mut self, date: NaiveDate, event: TrackEvent) { |
104 | if let Some(val) = self.stats.get_mut(&date) { | 104 | if let Some(val) = self.stats.get_mut(&date) { |
105 | *val = (val.0 ^ true).into(); | 105 | match event { |
106 | TrackEvent::Increment => *val = (val.0 ^ true).into(), | ||
107 | TrackEvent::Decrement => { | ||
108 | if val.0 { | ||
109 | *val = false.into(); | ||
110 | } else { | ||
111 | self.stats.remove(&date); | ||
112 | } | ||
113 | } | ||
114 | } | ||
106 | } else { | 115 | } else { |
107 | self.insert_entry(date, CustomBool(true)); | 116 | if event == TrackEvent::Increment { |
117 | self.insert_entry(date, CustomBool(true)); | ||
118 | } | ||
108 | } | 119 | } |
109 | } | 120 | } |
110 | fn set_view_month_offset(&mut self, offset: u32) { | 121 | fn set_view_month_offset(&mut self, offset: u32) { |