aboutsummaryrefslogtreecommitdiff
path: root/src/habit
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-07-23 17:53:59 +0100
committerAkshay <[email protected]>2020-07-23 17:53:59 +0100
commit91cb3ebf5b3af666b13f4821ff25f219fdccd7b9 (patch)
treec91d6cffd4d215b325e81bedfdcfdfdcea76a537 /src/habit
parent02bba52346d948e90fbc1b351486f0f1307c243d (diff)
parentd1d1aeb3d5aaa75f262467c5e683e76ce7a844ab (diff)
Merge branch 'feature/windows' of https://github.com/filalex77/dijo into feature/windows
Diffstat (limited to 'src/habit')
-rw-r--r--src/habit/bit.rs17
-rw-r--r--src/habit/count.rs7
-rw-r--r--src/habit/prelude.rs1
3 files changed, 20 insertions, 5 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) {
diff --git a/src/habit/count.rs b/src/habit/count.rs
index 1bdf920..d351758 100644
--- a/src/habit/count.rs
+++ b/src/habit/count.rs
@@ -84,12 +84,15 @@ impl Habit for Count {
84 if *val > 0 { 84 if *val > 0 {
85 *val -= 1 85 *val -= 1
86 } else { 86 } else {
87 *val = 0 87 self.stats.remove(&date);
88 }; 88 };
89 } 89 }
90 } 90 }
91 } else { 91 } else {
92 self.insert_entry(date, 1); 92 match event {
93 TrackEvent::Increment => self.insert_entry(date, 1),
94 _ => {}
95 };
93 } 96 }
94 } 97 }
95 fn set_view_month_offset(&mut self, offset: u32) { 98 fn set_view_month_offset(&mut self, offset: u32) {
diff --git a/src/habit/prelude.rs b/src/habit/prelude.rs
index 19b00a7..8335d6c 100644
--- a/src/habit/prelude.rs
+++ b/src/habit/prelude.rs
@@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
2use std::default; 2use std::default;
3use std::fmt; 3use std::fmt;
4 4
5#[derive(Debug, PartialEq)]
5pub enum TrackEvent { 6pub enum TrackEvent {
6 Increment, 7 Increment,
7 Decrement, 8 Decrement,