aboutsummaryrefslogtreecommitdiff
path: root/src/model/repetition.rs
diff options
context:
space:
mode:
authorJoris2022-02-20 09:33:55 +0100
committerJoris2022-02-20 09:33:55 +0100
commit1445e23a26c6581ad0c3f5b5016e47e95d224e9f (patch)
tree18bd4288fbcf52279a69de50be5bad6cc7db3c75 /src/model/repetition.rs
parent6c47403b11e7aaf1a22778bdc7615051779cb7bd (diff)
Save repetition in events
But don’t show repetead events for now.
Diffstat (limited to 'src/model/repetition.rs')
-rw-r--r--src/model/repetition.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/model/repetition.rs b/src/model/repetition.rs
new file mode 100644
index 0000000..80387d9
--- /dev/null
+++ b/src/model/repetition.rs
@@ -0,0 +1,26 @@
+use chrono::Weekday;
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
+pub enum Repetition {
+ Daily { frequency: u8 },
+ Monthly { frequency: MonthFrequency },
+ Yearly,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
+pub enum MonthFrequency {
+ Day { day: u8 },
+ FirstDay { day: Weekday },
+}
+
+// Validation
+
+pub fn validate_day(str: &str) -> Option<u8> {
+ let n = str.parse::<u8>().ok()?;
+ if n >= 1 && n <= 31 {
+ Some(n)
+ } else {
+ None
+ }
+}