Skip to content

Commit aa4a7a5

Browse files
MAGETWO-98886: Gift Card Accounts: expiration date subtracts one day
1 parent 4f6c78e commit aa4a7a5

File tree

1 file changed

+16
-3
lines changed
  • lib/internal/Magento/Framework/Data/Form/Element

1 file changed

+16
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ public function __construct(
5353
}
5454
}
5555

56+
/**
57+
* Check if a string is a date value
58+
*
59+
* @param string $value
60+
* @return bool
61+
*/
62+
private function isDate(string $value): bool
63+
{
64+
$date = date_parse($value);
65+
66+
return !empty($date['year']) && !empty($date['month']) && !empty($date['day']);
67+
}
68+
5669
/**
5770
* If script executes on x64 system, converts large numeric values to timestamp limit
5871
*
@@ -85,13 +98,13 @@ public function setValue($value)
8598
$this->_value = $value;
8699
return $this;
87100
}
88-
89101
try {
90102
if (preg_match('/^[0-9]+$/', $value)) {
91103
$this->_value = (new \DateTime())->setTimestamp($this->_toTimestamp($value));
104+
} else if (is_string($value) && $this->isDate($value)) {
105+
$this->_value = new \DateTime($value, new \DateTimeZone($this->localeDate->getConfigTimezone()));
92106
} else {
93-
$this->_value = new \DateTime($value);
94-
$this->_value->setTimezone(new \DateTimeZone($this->localeDate->getConfigTimezone()));
107+
$this->_value = '';
95108
}
96109
} catch (\Exception $e) {
97110
$this->_value = '';

0 commit comments

Comments
 (0)