diff --git a/quake_core/src/helper/quake_time.rs b/quake_core/src/helper/quake_time.rs index 2cfcb4f0..e3d2cb7c 100644 --- a/quake_core/src/helper/quake_time.rs +++ b/quake_core/src/helper/quake_time.rs @@ -5,8 +5,11 @@ use regex::Regex; const DATETIME_ZONE_FORMAT: &'static str = "%Y-%m-%d %H:%M:%S %z"; const DATETIME_FORMAT: &'static str = "%Y-%m-%d %H:%M:%S"; const DATE_FORMAT: &'static str = "%Y-%m-%d"; +const SIMPLE_DATE_FORMAT: &'static str = "%Y.%m.%d"; lazy_static! { + static ref SIMPLE_DATE_REGEX: Regex = + Regex::new(r"(?P\d{4}).(?P\d{2}).(?P\d{2})").unwrap(); static ref ISO8601_DATE_REGEX: Regex = Regex::new(r"(?P\d{4})-(?P\d{2})-(?P\d{2})").unwrap(); static ref ISO8601_DATE_TIME_REGEX: Regex = @@ -51,6 +54,12 @@ pub fn text_date_to_unix(text: &str) -> i64 { return naive_datetime.timestamp(); }; + if let Some(_caps) = SIMPLE_DATE_REGEX.captures(text) { + let naive_date = NaiveDate::parse_from_str(text, SIMPLE_DATE_FORMAT).unwrap(); + let naive_datetime = naive_date.and_hms(0, 0, 0); + return naive_datetime.timestamp(); + }; + timestamp } @@ -63,5 +72,6 @@ mod tests { assert_eq!(text_date_to_unix("2020-04-12 22:10:57 +08:00"), 1586700657); assert_eq!(text_date_to_unix("2020-04-12 22:10:57"), 1586729457); assert_eq!(text_date_to_unix("2021-12-09"), 1639008000); + assert_eq!(text_date_to_unix("2021.12.09"), 1639008000); } }