Skip to content

Commit b3409c5

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

File tree

2 files changed

+72
-1
lines changed
  • app/code/Magento/Catalog/Block/Product/View/Options/Type
  • lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime

2 files changed

+72
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function getCalendarDateHtml()
8282
$yearEnd = $this->_catalogProductOptionTypeDate->getYearEnd();
8383

8484
$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
85-
/** Escape invisible characters which are present in some locales and may corrupt formatting */
85+
/** Escape RTL characters which are present in some locales and corrupt formatting */
8686
$escapedDateFormat = preg_replace('/[^[:print:]]/', '', $dateFormat);
8787
$calendar = $this->getLayout()->createBlock(
8888
\Magento\Framework\View\Element\Html\Date::class
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Stdlib\Test\Unit\DateTime;
7+
8+
use Magento\Framework\Stdlib\DateTime\Timezone;
9+
10+
/**
11+
* Test for @see Timezone
12+
*/
13+
class TimezoneTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
17+
*/
18+
private $objectManager;
19+
20+
/**
21+
* @var \PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $scopeConfigMock;
24+
25+
protected function setUp()
26+
{
27+
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
28+
$this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
29+
->disableOriginalConstructor()
30+
->getMock();
31+
parent::setUp();
32+
}
33+
34+
/**
35+
* Test date parsing with different includeTime options
36+
*
37+
* @param string $date
38+
* @param string $locale
39+
* @param bool $includeTime
40+
* @param int $expectedTimestamp
41+
* @dataProvider dateIncludeTimeDataProvider
42+
*/
43+
public function testDateIncludeTime($date, $locale, $includeTime, $expectedTimestamp)
44+
{
45+
$this->scopeConfigMock->method('getValue')->willReturn('America/Chicago');
46+
/** @var Timezone $timezone */
47+
$timezone = $this->objectManager->getObject(Timezone::class, ['scopeConfig' => $this->scopeConfigMock]);
48+
49+
/** @var \DateTime $dateTime */
50+
$dateTime = $timezone->date($date, $locale, true, $includeTime);
51+
$this->assertEquals($expectedTimestamp, $dateTime->getTimestamp());
52+
}
53+
54+
public function dateIncludeTimeDataProvider()
55+
{
56+
return [
57+
'Parse date without time' => [
58+
'19/05/2017', // date
59+
'ar_KW', // locale
60+
false, // include time
61+
1495170000 // expected timestamp
62+
],
63+
'Parse date with time' => [
64+
'05/19/2017 00:01 am', // date
65+
'en_US', // locale
66+
true, // include time
67+
1495170060 // expected timestamp
68+
],
69+
];
70+
}
71+
}

0 commit comments

Comments
 (0)