@@ -239,7 +239,7 @@ impl Search {
239239 #[ cfg( feature = "geo" ) ]
240240 {
241241 let intersects: geo:: Geometry = intersects. try_into ( ) . map_err ( Box :: new) ?;
242- item. intersects ( & intersects) . map_err ( Error :: from )
242+ item. intersects ( & intersects)
243243 }
244244 #[ cfg( not( feature = "geo" ) ) ]
245245 {
@@ -363,26 +363,25 @@ fn expand_datetime_to_start(s: &str) -> Result<DateTime<FixedOffset>> {
363363 let midnight = NaiveTime :: from_hms_opt ( 0 , 0 , 0 ) . expect ( "midnight (0, 0, 0) is always valid" ) ;
364364
365365 // Case 1: Year only (e.g., "2023") -> 2023-01-01T00:00:00Z
366- if trimmed. len ( ) == 4 && trimmed. chars ( ) . all ( |c| c. is_numeric ( ) ) {
367- if let Ok ( year) = trimmed. parse :: < i32 > ( ) {
368- let date = NaiveDate :: from_ymd_opt ( year, 1 , 1 ) . ok_or ( Error :: InvalidYear ( year) ) ?;
369- let datetime = date. and_time ( midnight) ;
370- return Ok ( Utc . from_utc_datetime ( & datetime) . fixed_offset ( ) ) ;
371- }
366+ if trimmed. len ( ) == 4
367+ && trimmed. chars ( ) . all ( |c| c. is_numeric ( ) )
368+ && let Ok ( year) = trimmed. parse :: < i32 > ( )
369+ {
370+ let date = NaiveDate :: from_ymd_opt ( year, 1 , 1 ) . ok_or ( Error :: InvalidYear ( year) ) ?;
371+ let datetime = date. and_time ( midnight) ;
372+ return Ok ( Utc . from_utc_datetime ( & datetime) . fixed_offset ( ) ) ;
372373 }
373374
374375 // Case 2: Year-Month (e.g., "2023-01") -> 2023-01-01T00:00:00Z
375- if trimmed. len ( ) == 7 && trimmed. chars ( ) . nth ( 4 ) == Some ( '-' ) {
376- if let Some ( ( year_str, month_str) ) = trimmed. split_once ( '-' ) {
377- if let ( Ok ( year) , Ok ( month) ) = ( year_str. parse :: < i32 > ( ) , month_str. parse :: < u32 > ( ) ) {
378- if ( 1 ..=12 ) . contains ( & month) {
379- let date =
380- NaiveDate :: from_ymd_opt ( year, month, 1 ) . ok_or ( Error :: InvalidYear ( year) ) ?;
381- let datetime = date. and_time ( midnight) ;
382- return Ok ( Utc . from_utc_datetime ( & datetime) . fixed_offset ( ) ) ;
383- }
384- }
385- }
376+ if trimmed. len ( ) == 7
377+ && trimmed. chars ( ) . nth ( 4 ) == Some ( '-' )
378+ && let Some ( ( year_str, month_str) ) = trimmed. split_once ( '-' )
379+ && let ( Ok ( year) , Ok ( month) ) = ( year_str. parse :: < i32 > ( ) , month_str. parse :: < u32 > ( ) )
380+ && ( 1 ..=12 ) . contains ( & month)
381+ {
382+ let date = NaiveDate :: from_ymd_opt ( year, month, 1 ) . ok_or ( Error :: InvalidYear ( year) ) ?;
383+ let datetime = date. and_time ( midnight) ;
384+ return Ok ( Utc . from_utc_datetime ( & datetime) . fixed_offset ( ) ) ;
386385 }
387386
388387 // Case 3: ISO 8601 date (e.g., "2023-06-15") -> 2023-06-15T00:00:00Z
@@ -400,34 +399,34 @@ fn expand_datetime_to_end(s: &str) -> Result<DateTime<FixedOffset>> {
400399 let end_of_day = NaiveTime :: from_hms_opt ( 23 , 59 , 59 ) . expect ( "23:59:59 is always valid" ) ;
401400
402401 // Case 1: Year only (e.g., "2023") -> 2023-12-31T23:59:59Z
403- if trimmed. len ( ) == 4 && trimmed. chars ( ) . all ( |c| c. is_numeric ( ) ) {
404- if let Ok ( year) = trimmed. parse :: < i32 > ( ) {
405- let date = NaiveDate :: from_ymd_opt ( year, 12 , 31 ) . ok_or ( Error :: InvalidYear ( year) ) ?;
406- let datetime = date. and_time ( end_of_day) ;
407- return Ok ( Utc . from_utc_datetime ( & datetime) . fixed_offset ( ) ) ;
408- }
402+ if trimmed. len ( ) == 4
403+ && trimmed. chars ( ) . all ( |c| c. is_numeric ( ) )
404+ && let Ok ( year) = trimmed. parse :: < i32 > ( )
405+ {
406+ let date = NaiveDate :: from_ymd_opt ( year, 12 , 31 ) . ok_or ( Error :: InvalidYear ( year) ) ?;
407+ let datetime = date. and_time ( end_of_day) ;
408+ return Ok ( Utc . from_utc_datetime ( & datetime) . fixed_offset ( ) ) ;
409409 }
410410
411411 // Case 2: Year-Month (e.g., "2023-01") -> 2023-01-31T23:59:59Z (last day of month)
412- if trimmed. len ( ) == 7 && trimmed. chars ( ) . nth ( 4 ) == Some ( '-' ) {
413- if let Some ( ( year_str, month_str) ) = trimmed. split_once ( '-' ) {
414- if let ( Ok ( year) , Ok ( month) ) = ( year_str. parse :: < i32 > ( ) , month_str. parse :: < u32 > ( ) ) {
415- if ( 1 ..=12 ) . contains ( & month) {
416- // Get the last day of the month by going to first day of next month, then back one day
417- let last_day = if month == 12 {
418- NaiveDate :: from_ymd_opt ( year + 1 , 1 , 1 )
419- } else {
420- NaiveDate :: from_ymd_opt ( year, month + 1 , 1 )
421- }
422- . ok_or ( Error :: InvalidYear ( year) ) ?
423- . pred_opt ( )
424- . ok_or ( Error :: InvalidYear ( year) ) ?;
425-
426- let datetime = last_day. and_time ( end_of_day) ;
427- return Ok ( Utc . from_utc_datetime ( & datetime) . fixed_offset ( ) ) ;
428- }
429- }
412+ if trimmed. len ( ) == 7
413+ && trimmed. chars ( ) . nth ( 4 ) == Some ( '-' )
414+ && let Some ( ( year_str, month_str) ) = trimmed. split_once ( '-' )
415+ && let ( Ok ( year) , Ok ( month) ) = ( year_str. parse :: < i32 > ( ) , month_str. parse :: < u32 > ( ) )
416+ && ( 1 ..=12 ) . contains ( & month)
417+ {
418+ // Get the last day of the month by going to first day of next month, then back one day
419+ let last_day = if month == 12 {
420+ NaiveDate :: from_ymd_opt ( year + 1 , 1 , 1 )
421+ } else {
422+ NaiveDate :: from_ymd_opt ( year, month + 1 , 1 )
430423 }
424+ . ok_or ( Error :: InvalidYear ( year) ) ?
425+ . pred_opt ( )
426+ . ok_or ( Error :: InvalidYear ( year) ) ?;
427+
428+ let datetime = last_day. and_time ( end_of_day) ;
429+ return Ok ( Utc . from_utc_datetime ( & datetime) . fixed_offset ( ) ) ;
431430 }
432431
433432 // Case 3: ISO 8601 date (e.g., "2023-06-15") -> 2023-06-15T23:59:59Z
0 commit comments