aboutsummaryrefslogtreecommitdiff
path: root/src/habit/count.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-07-14 12:50:36 +0100
committerAkshay <[email protected]>2020-07-14 12:50:36 +0100
commit3ded40d04f49983e7907366536dbc94917cee666 (patch)
tree5e837246e3603249c9a7e4343d1afb762d5d0e71 /src/habit/count.rs
parent68ebbd1f753e0937bfaf07006daf1d6144c21bed (diff)
more boilerplate for auto-trackable habits
add funding.yml also :^)
Diffstat (limited to 'src/habit/count.rs')
-rw-r--r--src/habit/count.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/habit/count.rs b/src/habit/count.rs
index a0e0aee..1bdf920 100644
--- a/src/habit/count.rs
+++ b/src/habit/count.rs
@@ -3,6 +3,7 @@ use std::collections::HashMap;
3use chrono::NaiveDate; 3use chrono::NaiveDate;
4use serde::{Deserialize, Serialize}; 4use serde::{Deserialize, Serialize};
5 5
6use crate::habit::prelude::default_auto;
6use crate::habit::traits::Habit; 7use crate::habit::traits::Habit;
7use crate::habit::{TrackEvent, ViewMode}; 8use crate::habit::{TrackEvent, ViewMode};
8 9
@@ -12,6 +13,9 @@ pub struct Count {
12 stats: HashMap<NaiveDate, u32>, 13 stats: HashMap<NaiveDate, u32>,
13 goal: u32, 14 goal: u32,
14 15
16 #[serde(default = "default_auto")]
17 auto: bool,
18
15 #[serde(skip)] 19 #[serde(skip)]
16 view_month_offset: u32, 20 view_month_offset: u32,
17 21
@@ -20,11 +24,12 @@ pub struct Count {
20} 24}
21 25
22impl Count { 26impl Count {
23 pub fn new(name: impl AsRef<str>, goal: u32) -> Self { 27 pub fn new(name: impl AsRef<str>, goal: u32, auto: bool) -> Self {
24 return Count { 28 return Count {
25 name: name.as_ref().to_owned(), 29 name: name.as_ref().to_owned(),
26 stats: HashMap::new(), 30 stats: HashMap::new(),
27 goal, 31 goal,
32 auto,
28 view_month_offset: 0, 33 view_month_offset: 0,
29 view_mode: ViewMode::Day, 34 view_mode: ViewMode::Day,
30 }; 35 };
@@ -99,4 +104,7 @@ impl Habit for Count {
99 fn view_mode(&self) -> ViewMode { 104 fn view_mode(&self) -> ViewMode {
100 self.view_mode 105 self.view_mode
101 } 106 }
107 fn is_auto(&self) -> bool {
108 self.auto
109 }
102} 110}