@@ -250,9 +250,9 @@ protected function validator($varInput)
250250
251251 // Convert date formats into timestamps (check the eval setting first -> #3063)
252252 $ rgxp = $ arrField ['eval ' ]['rgxp ' ];
253- if (($ rgxp == 'date ' || $ rgxp == 'time ' || $ rgxp == 'datim ' ) && $ varValue != '' )
253+ if (! $ objWidget -> hasErrors () && ($ rgxp == 'date ' || $ rgxp == 'time ' || $ rgxp == 'datim ' ) && $ varValue != '' )
254254 {
255- $ objDate = new Date ($ varValue , $ GLOBALS [ ' TL_CONFIG ' ][ $ rgxp . ' Format ' ] );
255+ $ objDate = new Date ($ varValue ,$ this -> getNumericDateFormat ( $ rgxp) );
256256 $ varValue = $ objDate ->tstamp ;
257257 }
258258
@@ -526,7 +526,7 @@ public function generate()
526526 if ($ arrField ['eval ' ]['datepicker ' ])
527527 {
528528 $ rgxp = $ arrField ['eval ' ]['rgxp ' ];
529- $ format = $ GLOBALS [ ' TL_CONFIG ' ][ $ rgxp . ' Format ' ] ;
529+ $ format = $ this -> getNumericDateFormat ( $ rgxp) ;
530530
531531 switch ($ rgxp )
532532 {
@@ -673,7 +673,7 @@ protected function getMcWDatePickerString($strId, $strKey, $rgxp)
673673 {
674674 if (version_compare (VERSION , '2.11 ' , '< ' ))
675675 {
676- $ format = $ GLOBALS [ ' TL_CONFIG ' ][ $ rgxp . ' Format ' ] ;
676+ $ format = $ this -> getNumericDateFormat ( $ rgxp) ;
677677 switch ($ rgxp )
678678 {
679679 case 'datim ' :
@@ -711,7 +711,7 @@ protected function getMcWDatePickerString($strId, $strKey, $rgxp)
711711
712712 elseif (version_compare (VERSION ,'3.3 ' ,'< ' )) {
713713
714- $ format = Date::formatToJs ($ GLOBALS [ ' TL_CONFIG ' ][ $ rgxp . ' Format ' ] );
714+ $ format = Date::formatToJs ($ this -> getNumericDateFormat ( $ rgxp) );
715715 switch ($ rgxp )
716716 {
717717 case 'datim ' :
@@ -747,7 +747,7 @@ protected function getMcWDatePickerString($strId, $strKey, $rgxp)
747747
748748 else
749749 {
750- $ format = Date::formatToJs ($ GLOBALS [ ' TL_CONFIG ' ][ $ rgxp . ' Format ' ] );
750+ $ format = Date::formatToJs ($ this -> getNumericDateFormat ( $ rgxp) );
751751 switch ($ rgxp )
752752 {
753753 case 'datim ' :
@@ -949,9 +949,15 @@ protected function initializeWidget(&$arrField, $intRow, $strKey, $varValue)
949949
950950 // Convert date formats into timestamps (check the eval setting first -> #3063)
951951 $ rgxp = $ arrField ['eval ' ]['rgxp ' ];
952+ $ dateFormatErrorMsg ="" ;
952953 if (($ rgxp == 'date ' || $ rgxp == 'time ' || $ rgxp == 'datim ' ) && $ varValue != '' )
953954 {
954- $ objDate = new Date ($ varValue , $ GLOBALS ['TL_CONFIG ' ][$ rgxp . 'Format ' ]);
955+ try {
956+ $ objDate = new Date ($ varValue , $ this ->getNumericDateFormat ($ rgxp ));
957+ }catch (\Exception $ e ){
958+ $ dateFormatErrorMsg =$ e ->getMessage ();
959+ }
960+
955961 $ varValue = $ objDate ->tstamp ;
956962 }
957963
@@ -973,6 +979,9 @@ protected function initializeWidget(&$arrField, $intRow, $strKey, $varValue)
973979 $ objWidget ->storeValues = true ;
974980 $ objWidget ->xlabel = $ xlabel ;
975981 $ objWidget ->currentRecord = $ this ->currentRecord ;
982+ if (!empty ($ dateFormatErrorMsg )){
983+ $ objWidget ->addError ($ e ->getMessage ());
984+ }
976985
977986 return $ objWidget ;
978987 }
@@ -1234,4 +1243,15 @@ protected function generateButtonString($level = 0)
12341243 return $ return ;
12351244 }
12361245
1246+ /**
1247+ * Get Time/Date-format from global config (BE) or Page settings (FE)
1248+ * @param $rgxp
1249+ *
1250+ * @return mixed
1251+ */
1252+ private function getNumericDateFormat ($ rgxp ){
1253+ return call_user_func (array ("\Contao\Date " ,"getNumeric " .ucfirst ($ rgxp )."Format " ));
1254+ }
1255+
1256+
12371257}
0 commit comments