From 30ffe4d73445a4514ab16ea60854deb8f5185340 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Fri, 15 May 2020 20:49:05 -0300 Subject: [PATCH] One single string for the format --- src/eventlist/event.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/eventlist/event.rs b/src/eventlist/event.rs index 6e45458..548eea9 100644 --- a/src/eventlist/event.rs +++ b/src/eventlist/event.rs @@ -26,6 +26,8 @@ use serde_derive::Deserialize; use serde_derive::Serialize; use uuid::Uuid; +static DATE_FORMAT: &str = "%Y-%m-%d %H:%M:%S"; + #[derive(Serialize, Deserialize, Debug)] pub struct Date { year: i32, @@ -103,7 +105,7 @@ impl Event { // TODO result this pub fn new_on_date(description: &str, date: &str) -> Self { let fake_datetime = format!("{} 00:00:00", date); - if let Ok(dt) = Local.datetime_from_str(&fake_datetime, "%Y-%m-%d %H:%M:%S") { + if let Ok(dt) = Local.datetime_from_str(&fake_datetime, DATE_FORMAT) { // TODO turn format into static Self { id: uuid(), @@ -117,7 +119,7 @@ impl Event { pub fn new_on_date_time(description: &str, date: &str, time: &str) -> Self { let fake_datetime = format!("{} {}:00", date, time); - if let Ok(dt) = Local.datetime_from_str(&fake_datetime, "%Y-%m-%d %H:%M:%S") { + if let Ok(dt) = Local.datetime_from_str(&fake_datetime, DATE_FORMAT) { Self { id: uuid(), description: description.into(),