diff --git a/frontend/rust-lib/flowy-date/src/event_handler.rs b/frontend/rust-lib/flowy-date/src/event_handler.rs index aad22de2518ef..bf797c07f2212 100644 --- a/frontend/rust-lib/flowy-date/src/event_handler.rs +++ b/frontend/rust-lib/flowy-date/src/event_handler.rs @@ -25,7 +25,7 @@ pub(crate) async fn query_date_handler( let year_match = year_regex().find(&query).unwrap(); let formatted = year_match .and_then(|capture| capture.as_str().parse::().ok()) - .and_then(|year| NaiveDate::from_ymd_opt(year, naive_date.month0(), naive_date.day0())) + .and_then(|year| NaiveDate::from_ymd_opt(year, naive_date.month(), naive_date.day())) .map(|date| date.to_string()) .unwrap_or_else(|| naive_date.to_string()); @@ -34,3 +34,15 @@ pub(crate) async fn query_date_handler( None => Err(FlowyError::internal().with_context("Failed to parse date from")), } } + +#[cfg(test)] +mod tests { + use super::*; + + #[tokio::test] + async fn parses_year_from_query() { + let data = AFPluginData(DateQueryPB { query: "June 5 2024".into() }); + let result = query_date_handler(data).await.expect("handler should succeed"); + assert_eq!(result.date, "2024-06-05"); + } +}