Skip to content

Commit a8ebabe

Browse files
committed
MAGETWO-71669: Incorrect date format with Arabic language locale
- Format date that was not formatted yet;
1 parent 7347c02 commit a8ebabe

File tree

1 file changed

+5
-5
lines changed
  • app/code/Magento/Eav/Model/Entity/Attribute/Backend

1 file changed

+5
-5
lines changed

app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface
3737
public function beforeSave($object)
3838
{
3939
$attributeName = $this->getAttribute()->getName();
40-
$_formated = $object->getData($attributeName . '_is_formated');
41-
if (!$_formated && $object->hasData($attributeName)) {
40+
$pattern = '/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/';
41+
// format only date that was not formatted yet
42+
if ($object->hasData($attributeName) && !preg_match($pattern, $object->getData($attributeName))) {
4243
try {
4344
$value = $this->formatDate($object->getData($attributeName));
4445
} catch (\Exception $e) {
@@ -50,7 +51,6 @@ public function beforeSave($object)
5051
}
5152

5253
$object->setData($attributeName, $value);
53-
$object->setData($attributeName . '_is_formated', true);
5454
}
5555

5656
return $this;
@@ -60,7 +60,7 @@ public function beforeSave($object)
6060
* Prepare date for save in DB
6161
*
6262
* string format used from input fields (all date input fields need apply locale settings)
63-
* int value can be declared in code (this meen whot we use valid date)
63+
* int value can be declared in code (this means that we use valid date)
6464
*
6565
* @param string|int|\DateTime $date
6666
* @return string
@@ -74,9 +74,9 @@ public function formatDate($date)
7474
if (is_scalar($date) && preg_match('/^[0-9]+$/', $date)) {
7575
$date = (new \DateTime())->setTimestamp($date);
7676
} elseif (!($date instanceof \DateTime)) {
77-
// normalized format expecting Y-m-d[ H:i:s] - time is optional
7877
$date = $this->_localeDate->date($date, null, false);
7978
}
79+
// normalized format expecting Y-m-d [H:i:s] - time is optional
8080
return $date->format('Y-m-d H:i:s');
8181
}
8282
}

0 commit comments

Comments
 (0)