Skip to content

Commit 2747328

Browse files
author
Alex Paliarush
committed
MAGETWO-68976: [Magento Cloud] Incorrect date format with Arabic language locale
1 parent 6086595 commit 2747328

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

app/code/Magento/Catalog/Block/Product/View/Options/Type/Date.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public function getCalendarDateHtml()
8181
$yearStart = $this->_catalogProductOptionTypeDate->getYearStart();
8282
$yearEnd = $this->_catalogProductOptionTypeDate->getYearEnd();
8383

84+
$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
85+
/** Escape invisible characters which are present in some locales and may corrupt formatting */
86+
$escapedDateFormat = preg_replace('/[^[:print:]]/', '', $dateFormat);
8487
$calendar = $this->getLayout()->createBlock(
8588
\Magento\Framework\View\Element\Html\Date::class
8689
)->setId(
@@ -92,7 +95,7 @@ public function getCalendarDateHtml()
9295
)->setImage(
9396
$this->getViewFileUrl('Magento_Theme::calendar.png')
9497
)->setDateFormat(
95-
$this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT)
98+
$escapedDateFormat
9699
)->setValue(
97100
$value
98101
)->setYearsRange(

app/code/Magento/Catalog/Model/Product/Option/Type/Date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function prepareForCart()
155155

156156
if ($this->_dateExists()) {
157157
if ($this->useCalendar()) {
158-
$timestamp += (new \DateTime($value['date']))->getTimestamp();
158+
$timestamp += $this->_localeDate->date($value['date'], null, true, false)->getTimestamp();
159159
} else {
160160
$timestamp += mktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
161161
}

lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function getDateTimeFormat($type)
153153
* {@inheritdoc}
154154
* @SuppressWarnings(PHPMD.NPathComplexity)
155155
*/
156-
public function date($date = null, $locale = null, $useTimezone = true)
156+
public function date($date = null, $locale = null, $useTimezone = true, $includeTime = true)
157157
{
158158
$locale = $locale ?: $this->_localeResolver->getLocale();
159159
$timezone = $useTimezone
@@ -165,10 +165,11 @@ public function date($date = null, $locale = null, $useTimezone = true)
165165
} elseif ($date instanceof \DateTime) {
166166
return $date->setTimezone(new \DateTimeZone($timezone));
167167
} elseif (!is_numeric($date)) {
168+
$timeType = $includeTime ? \IntlDateFormatter::SHORT : \IntlDateFormatter::NONE;
168169
$formatter = new \IntlDateFormatter(
169170
$locale,
170171
\IntlDateFormatter::SHORT,
171-
\IntlDateFormatter::SHORT,
172+
$timeType,
172173
new \DateTimeZone($timezone)
173174
);
174175
$date = $formatter->parse($date) ?: (new \DateTime($date))->getTimestamp();

lib/internal/Magento/Framework/Stdlib/DateTime/TimezoneInterface.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ public function getDateTimeFormat($type);
6060
/**
6161
* Create \DateTime object for current locale
6262
*
63-
* @param mixed $date
63+
* @param mixed $date
6464
* @param string $locale
65-
* @param bool $useTimezone
65+
* @param bool $useTimezone
66+
* @param bool $includeTime
6667
* @return \DateTime
6768
*/
68-
public function date($date = null, $locale = null, $useTimezone = true);
69+
public function date($date = null, $locale = null, $useTimezone = true, $includeTime = true);
6970

7071
/**
7172
* Create \DateTime object with date converted to scope timezone and scope Locale

0 commit comments

Comments
 (0)