99 *
1010 * @author Magento Core Team <[email protected] > 1111 */
12+
1213namespace Magento \Framework \Data \Form \Element ;
1314
1415use Magento \Framework \Escaper ;
1516use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
1617
18+ /**
19+ * Date element
20+ */
1721class Date extends AbstractElement
1822{
1923 /**
@@ -50,8 +54,7 @@ public function __construct(
5054 }
5155
5256 /**
53- * If script executes on x64 system, converts large
54- * numeric values to timestamp limit
57+ * If script executes on x64 system, converts large numeric values to timestamp limit
5558 *
5659 * @param int $value
5760 * @return int
@@ -82,13 +85,14 @@ public function setValue($value)
8285 $ this ->_value = $ value ;
8386 return $ this ;
8487 }
85- if (preg_match ('/^[0-9]+$/ ' , $ value )) {
86- $ this ->_value = (new \DateTime ())->setTimestamp ($ this ->_toTimestamp ($ value ));
87- return $ this ;
88- }
8988
9089 try {
91- $ this ->_value = new \DateTime ($ value , new \DateTimeZone ($ this ->localeDate ->getConfigTimezone ()));
90+ if (preg_match ('/^[0-9]+$/ ' , $ value )) {
91+ $ this ->_value = (new \DateTime ())->setTimestamp ($ this ->_toTimestamp ($ value ));
92+ } else {
93+ $ this ->_value = new \DateTime ($ value );
94+ $ this ->_value ->setTimezone (new \DateTimeZone ($ this ->localeDate ->getConfigTimezone ()));
95+ }
9296 } catch (\Exception $ e ) {
9397 $ this ->_value = '' ;
9498 }
@@ -97,6 +101,7 @@ public function setValue($value)
97101
98102 /**
99103 * Get date value as string.
104+ *
100105 * Format can be specified, or it will be taken from $this->getFormat()
101106 *
102107 * @param string $format (compatible with \DateTime)
0 commit comments