Skip to content

Commit 5d52e3d

Browse files
committed
Merge branch 'ACP2E-347' of https://github.com/magento-l3/magento2ce into PR-2022-02-15-CE2
2 parents 0751c41 + 7e7cc3d commit 5d52e3d

File tree

2 files changed

+34
-31
lines changed
  • dev/tests/integration/testsuite/Magento/Framework/Data/Form/Element
  • lib/internal/Magento/Framework/Data/Form/Element

2 files changed

+34
-31
lines changed

dev/tests/integration/testsuite/Magento/Framework/Data/Form/Element/DateTest.php

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,38 +50,43 @@ public function testGetValue(array $data, string $expect): void
5050
*/
5151
public function getValueDataProvider(): array
5252
{
53-
$testTimestamp = strtotime('2014-05-18 12:08:16');
54-
$date = new \DateTime('@' . $testTimestamp);
55-
return [
56-
[
53+
$stringDates = ['2020-05-18 12:08:16', '1920-10-25 10:10:10', '2122-01-11 10:30:00'];
54+
$testTimestamps = [strtotime($stringDates[0]), strtotime($stringDates[1]), strtotime($stringDates[2])];
55+
$dates = [new \DateTime($stringDates[0]), new \DateTime($stringDates[1]), new \DateTime($stringDates[2])];
56+
$data = [];
57+
foreach ($testTimestamps as $key => $testTimestamp) {
58+
$data[$key] = [
5759
[
58-
'date_format' => 'MM/d/yy',
59-
'time_format' => 'h:mm a',
60-
'value' => $testTimestamp,
60+
[
61+
'date_format' => 'MM/d/yy',
62+
'time_format' => 'h:mm a',
63+
'value' => $testTimestamp,
64+
],
65+
$dates[$key]->format('m/j/y g:i A'),
6166
],
62-
$date->format('m/j/y g:i A'),
63-
],
64-
[
6567
[
66-
'time_format' => 'h:mm a',
67-
'value' => $testTimestamp,
68+
[
69+
'time_format' => 'h:mm a',
70+
'value' => $testTimestamp,
71+
],
72+
$dates[$key]->format('g:i A'),
6873
],
69-
$date->format('g:i A'),
70-
],
71-
[
7274
[
73-
'date_format' => 'MM/d/yy',
74-
'value' => $testTimestamp,
75+
[
76+
'date_format' => 'MM/d/yy',
77+
'value' => $testTimestamp,
78+
],
79+
$dates[$key]->format('m/j/y'),
7580
],
76-
$date->format('m/j/y'),
77-
],
78-
[
7981
[
80-
'date_format' => 'd-MM-Y',
81-
'value' => $date->format('d-m-Y'),
82+
[
83+
'date_format' => 'd-MM-Y',
84+
'value' => $dates[$key]->format('d-m-Y'),
85+
],
86+
$dates[$key]->format('d-m-Y'),
8287
],
83-
$date->format('d-m-Y'),
84-
],
85-
];
88+
];
89+
}
90+
return array_merge($data[0], $data[1]);
8691
}
8792
}

lib/internal/Magento/Framework/Data/Form/Element/Date.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,15 @@ private function isDate(string $value): bool
6767
}
6868

6969
/**
70+
* Initial scope of method was to limit timestamp on x64 systems to mimic x32 systems,
71+
* but keeping the method for compatibility:
7072
* If script executes on x64 system, converts large numeric values to timestamp limit
7173
*
7274
* @param int $value
7375
* @return int
7476
*/
7577
protected function _toTimestamp($value)
7678
{
77-
$value = (int)$value;
78-
if ($value > 3155760000) {
79-
$value = 0;
80-
}
81-
8279
return $value;
8380
}
8481

@@ -99,7 +96,7 @@ public function setValue($value)
9996
return $this;
10097
}
10198
try {
102-
if (preg_match('/^[0-9]+$/', $value)) {
99+
if (preg_match('/^[\-]{0,1}[0-9]+$/', $value)) {
103100
$this->_value = (new \DateTime())->setTimestamp($this->_toTimestamp($value));
104101
} elseif (is_string($value) && $this->isDate($value)) {
105102
$this->_value = new \DateTime($value, new \DateTimeZone($this->localeDate->getConfigTimezone()));
@@ -168,6 +165,7 @@ public function getElementHtml()
168165
$dateFormat = $this->getDateFormat() ?: $this->getFormat();
169166
$timeFormat = $this->getTimeFormat();
170167
if (empty($dateFormat)) {
168+
// phpcs:ignore Magento2.Exceptions.DirectThrow
171169
throw new \Exception(
172170
'Output format is not specified. ' .
173171
'Please specify "format" key in constructor, or set it using setFormat().'

0 commit comments

Comments
 (0)