@@ -99,11 +99,34 @@ public function isRequired()
99
99
*/
100
100
public function setDate ($ date )
101
101
{
102
- $ this ->setTime ($ date ? strtotime ($ date ) : false );
102
+ $ this ->setTime ($ this -> filterTime ($ date ));
103
103
$ this ->setValue ($ this ->applyOutputFilter ($ date ));
104
104
return $ this ;
105
105
}
106
106
107
+ /**
108
+ * Sanitizes time
109
+ *
110
+ * @param mixed $value
111
+ * @return bool|int
112
+ */
113
+ private function filterTime ($ value )
114
+ {
115
+ $ time = false ;
116
+ if ($ value ) {
117
+ if ($ value instanceof \DateTimeInterface) {
118
+ $ time = $ value ->getTimestamp ();
119
+ } elseif (is_numeric ($ value )) {
120
+ $ time = $ value ;
121
+ } elseif (is_string ($ value )) {
122
+ $ time = strtotime ($ value );
123
+ $ time = $ time === false ? $ this ->_localeDate ->date ($ value , null , false , false )->getTimestamp () : $ time ;
124
+ }
125
+ }
126
+
127
+ return $ time ;
128
+ }
129
+
107
130
/**
108
131
* Return Data Form Filter or false
109
132
*
@@ -200,21 +223,23 @@ public function getStoreLabel($attributeCode)
200
223
*/
201
224
public function getFieldHtml ()
202
225
{
203
- $ this ->dateElement ->setData ([
204
- 'extra_params ' => $ this ->getHtmlExtraParams (),
205
- 'name ' => $ this ->getHtmlId (),
206
- 'id ' => $ this ->getHtmlId (),
207
- 'class ' => $ this ->getHtmlClass (),
208
- 'value ' => $ this ->getValue (),
209
- 'date_format ' => $ this ->getDateFormat (),
210
- 'image ' => $ this ->getViewFileUrl ('Magento_Theme::calendar.png ' ),
211
- 'years_range ' => '-120y:c+nn ' ,
212
- 'max_date ' => '-1d ' ,
213
- 'change_month ' => 'true ' ,
214
- 'change_year ' => 'true ' ,
215
- 'show_on ' => 'both ' ,
216
- 'first_day ' => $ this ->getFirstDay ()
217
- ]);
226
+ $ this ->dateElement ->setData (
227
+ [
228
+ 'extra_params ' => $ this ->getHtmlExtraParams (),
229
+ 'name ' => $ this ->getHtmlId (),
230
+ 'id ' => $ this ->getHtmlId (),
231
+ 'class ' => $ this ->getHtmlClass (),
232
+ 'value ' => $ this ->getValue (),
233
+ 'date_format ' => $ this ->getDateFormat (),
234
+ 'image ' => $ this ->getViewFileUrl ('Magento_Theme::calendar.png ' ),
235
+ 'years_range ' => '-120y:c+nn ' ,
236
+ 'max_date ' => '-1d ' ,
237
+ 'change_month ' => 'true ' ,
238
+ 'change_year ' => 'true ' ,
239
+ 'show_on ' => 'both ' ,
240
+ 'first_day ' => $ this ->getFirstDay ()
241
+ ]
242
+ );
218
243
return $ this ->dateElement ->getHtml ();
219
244
}
220
245
0 commit comments