Skip to content

Commit 60e11cd

Browse files
committed
MAGETWO-61004: Show correct store local date - use timezone configuration
1 parent 38108c7 commit 60e11cd

File tree

2 files changed

+19
-10
lines changed
  • app/code/Magento/Ui/Component/Form/Element/DataType
  • dev/tests/functional/tests/app/Magento/Backend/Test/Fixture/Source

2 files changed

+19
-10
lines changed

app/code/Magento/Ui/Component/Form/Element/DataType/Date.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,14 @@ public function __construct(
6060
public function prepare()
6161
{
6262
$config = $this->getData('config');
63-
64-
if (!isset($config['timeOffset'])) {
65-
$config['timeOffset'] = (new \DateTime(
66-
'now',
67-
new \DateTimeZone(
68-
$this->localeDate->getConfigTimezone()
69-
)
70-
))->getOffset();
63+
if (!isset($config['storeTimeZone'])) {
64+
$storeTimeZone = $this->localeDate->getConfigTimezone();
65+
$config['storeTimeZone'] = $storeTimeZone;
7166
}
72-
67+
// Set date format pattern by current locale
68+
$localeDateFormat = $this->localeDate->getDateFormat();
69+
$config['options']['dateFormat'] = $localeDateFormat;
70+
$config['outputDateFormat'] = $localeDateFormat;
7371
$this->setData('config', $config);
7472

7573
parent::prepare();

dev/tests/functional/tests/app/Magento/Backend/Test/Fixture/Source/Date.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
namespace Magento\Backend\Test\Fixture\Source;
88

9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Mtf\Fixture\DataSource;
1011

1112
/**
1213
* Class Date.
1314
*
1415
* Data keys:
1516
* - pattern (Format a local time/date with delta, e.g. 'm/d/Y -3 days' = current day - 3 days)
17+
* - apply_timezone (true if it is needed to apply timezone)
1618
*/
1719
class Date extends DataSource
1820
{
@@ -35,7 +37,16 @@ public function __construct(array $params, $data = [])
3537
if (!$timestamp) {
3638
throw new \Exception('Invalid date format for "' . $this->params['attribute_code'] . '" field');
3739
}
38-
$date = date(str_replace($delta, '', $data['pattern']), $timestamp);
40+
if (isset($data['apply_timezone']) && $data['apply_timezone'] === true) {
41+
$timezone = ObjectManager::getInstance()
42+
->get(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
43+
$date = new \DateTime();
44+
$date->setTimestamp($timestamp);
45+
$date->setTimezone(new \DateTimeZone($timezone->getConfigTimezone()));
46+
$date = $date->format(str_replace($delta, '', $data['pattern']));
47+
} else {
48+
$date = date(str_replace($delta, '', $data['pattern']), $timestamp);
49+
}
3950
if (!$date) {
4051
$date = date('m/d/Y');
4152
}

0 commit comments

Comments
 (0)