9
9
*
10
10
* @author Magento Core Team <[email protected] >
11
11
*/
12
+
12
13
namespace Magento \Framework \Data \Form \Element ;
13
14
14
15
use Magento \Framework \Escaper ;
15
16
use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
16
17
18
+ /**
19
+ * Date element
20
+ */
17
21
class Date extends AbstractElement
18
22
{
19
23
/**
@@ -50,8 +54,7 @@ public function __construct(
50
54
}
51
55
52
56
/**
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
55
58
*
56
59
* @param int $value
57
60
* @return int
@@ -82,13 +85,14 @@ public function setValue($value)
82
85
$ this ->_value = $ value ;
83
86
return $ this ;
84
87
}
85
- if (preg_match ('/^[0-9]+$/ ' , $ value )) {
86
- $ this ->_value = (new \DateTime ())->setTimestamp ($ this ->_toTimestamp ($ value ));
87
- return $ this ;
88
- }
89
88
90
89
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
+ }
92
96
} catch (\Exception $ e ) {
93
97
$ this ->_value = '' ;
94
98
}
@@ -97,6 +101,7 @@ public function setValue($value)
97
101
98
102
/**
99
103
* Get date value as string.
104
+ *
100
105
* Format can be specified, or it will be taken from $this->getFormat()
101
106
*
102
107
* @param string $format (compatible with \DateTime)
0 commit comments