diff options
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/event.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/model/event.rs b/src/model/event.rs index a0bdc85..27587bc 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -1,10 +1,12 @@ use chrono::Timelike; use chrono::{NaiveDate, NaiveTime}; +use uuid::Uuid; pub static DATE_FORMAT: &str = "%d/%m/%Y"; #[derive(Debug, Clone)] pub struct Event { + pub id: Uuid, pub date: NaiveDate, pub start: Option<NaiveTime>, pub end: Option<NaiveTime>, @@ -50,7 +52,7 @@ fn parse_time(t: &str) -> Option<NaiveTime> { // Validation -pub fn validate(date: String, name: String, start: String, end: String) -> Option<Event> { +pub fn validate(id: Uuid, date: String, name: String, start: String, end: String) -> Option<Event> { let start = validate_time(start)?; let end = validate_time(end)?; @@ -60,6 +62,7 @@ pub fn validate(date: String, name: String, start: String, end: String) -> Optio } Some(Event { + id, date: NaiveDate::parse_from_str(&date, DATE_FORMAT).ok()?, name: validate_name(name)?, start, |