@@ -796,10 +796,40 @@ public function search_form($parameters = null)
796796 // Add param value pair into search_fields array
797797 $ search_fields [$ key ] = $ param ;
798798
799- }elseif (in_array ($ key , $ a_text_params ) or in_array ( $ key , $ this -> a_search_fields_date ) ){
799+ }elseif (in_array ($ key , $ a_text_params )){
800800 // Decode strings in URL
801801 $ search_fields [$ key ] = urldecode ($ param );
802+
803+ }elseif (in_array ($ key , $ this ->a_search_fields_date )){
804+ // Decode strings in URL
805+ $ date = urldecode ($ param );
802806
807+ if (ctype_digit ($ date ) and strlen ($ date ) == 4 ){
808+ // Create a formatted date from year
809+ $ search_fields [$ key ] = Carbon::createFromFormat ('Y ' , $ date )->startOfYear ()->format (trans ('panichd::lang.datetime-format ' ));
810+
811+ // Specify date type if it's not set
812+ if (!isset ($ search_fields [$ key . '_type ' ])) $ search_fields [$ key . '_type ' ] = 'exact_year ' ;
813+
814+ }else {
815+ try {
816+ // Check if it's a full and formatted date time string
817+ Carbon::createFromFormat (trans ('panichd::lang.datetime-format ' ), $ date );
818+ $ search_fields [$ key ] = $ date ;
819+
820+ } catch (\Exception $ e ) {
821+ try {
822+ // Check if it's a date string
823+ $ datetime = Carbon::createFromFormat (trans ('panichd::lang.date-format ' ), $ date )->startOfDay ()->format (trans ('panichd::lang.datetime-format ' ));
824+ $ search_fields [$ key ] = $ datetime ;
825+ if (!isset ($ search_fields [$ key . '_type ' ])) $ search_fields [$ key . '_type ' ] = 'exact_day ' ;
826+
827+ }catch (\Exception $ e ) {
828+ // Don't register the date field
829+ }
830+ }
831+ }
832+
803833 }elseif (in_array (str_replace ('_type ' , '' , $ key ), $ this ->a_search_fields_date ) and in_array ($ param , $ this ->a_search_fields_date_types )){
804834 // Get date field related type
805835 $ search_fields [$ key ] = $ param ;
0 commit comments