Skip to content

Commit a65e016

Browse files
author
Igor Melnikov
committed
Merge branch 'time_zone' of https://github.corp.magento.com/magento2/magento2ce into time_zone
2 parents 5c09976 + cc96ed2 commit a65e016

File tree

14 files changed

+44
-23
lines changed

14 files changed

+44
-23
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ public function setValue($value)
200200
protected function _convertDate($date)
201201
{
202202
$adminTimeZone = new \DateTimeZone(
203-
$this->_scopeConfig->getValue(
204-
$this->_localeDate->getDefaultTimezonePath(),
205-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
206-
)
203+
$this->_localeDate->getConfigTimezone()
207204
);
208205
$formatter = new \IntlDateFormatter(
209206
$this->localeResolver->getLocale(),

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ protected function _convertDate($date)
6969
if ($this->getColumn()->getFilterTime()) {
7070
try {
7171
$adminTimeZone = new \DateTimeZone(
72-
$this->_scopeConfig->getValue(
73-
$this->_localeDate->getDefaultTimezonePath(),
74-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
75-
)
72+
$this->_localeDate->getConfigTimezone()
7673
);
7774
$simpleRes = new \DateTime($date, $adminTimeZone);
7875
$simpleRes->setTimezone(new \DateTimeZone('UTC'));

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Date.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ protected function _getFormat()
7575
public function render(\Magento\Framework\DataObject $row)
7676
{
7777
if ($data = $row->getData($this->getColumn()->getIndex())) {
78+
$timezone = $this->getColumn()->getTimezone() !== false ? $this->_localeDate->getConfigTimezone() : 'UTC';
7879
return $this->dateTimeFormatter->formatObject(
7980
$this->_localeDate->date(
80-
new \DateTime($data, new \DateTimeZone($this->_localeDate->getConfigTimezone()))
81+
new \DateTime(
82+
$data,
83+
new \DateTimeZone($timezone)
84+
)
8185
),
8286
$this->_getFormat()
8387
);

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Datetime.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ class Datetime extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Abstra
2020
public function render(\Magento\Framework\DataObject $row)
2121
{
2222
$format = $this->getColumn()->getFormat();
23-
if ($data = $this->_getValue($row)) {
24-
return $this->_localeDate->formatDate(
25-
$data,
23+
if ($date = $this->_getValue($row)) {
24+
return $this->_localeDate->formatDateTime(
25+
$date instanceof \DateTimeInterface ? $date : new \DateTime($date),
2626
$format ?: \IntlDateFormatter::MEDIUM,
27-
true
27+
$format ?: \IntlDateFormatter::MEDIUM,
28+
null,
29+
$this->getColumn()->getTimezone() !== false ? null : 'UTC'
2830
);
2931
}
3032
return $this->getColumn()->getDefault();

app/code/Magento/Customer/Test/Unit/Ui/Component/ColumnFactoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public function testCreate()
9191
'label' => 'Label',
9292
'value' => 'Value'
9393
]
94-
]
94+
],
95+
'component' => 'Magento_Ui/js/grid/columns/column',
9596
],
9697
],
9798
'context' => $this->context,

app/code/Magento/Customer/Ui/Component/ColumnFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ public function create(array $attributeData, $columnName, $context, array $confi
6060
'dataType' => $this->getDataType($attributeData[AttributeMetadata::FRONTEND_INPUT]),
6161
'align' => 'left',
6262
'visible' => (bool)$attributeData[AttributeMetadata::IS_VISIBLE_IN_GRID],
63+
'component' => $this->getJsComponent($this->getDataType($attributeData[AttributeMetadata::FRONTEND_INPUT])),
6364
], $config);
65+
if ($attributeData[AttributeMetadata::FRONTEND_INPUT] == 'date') {
66+
$config['dateFormat'] = 'MMM d, y';
67+
$config['timezone'] = false;
68+
}
6469
if (count($attributeData[AttributeMetadata::OPTIONS]) && !isset($config[AttributeMetadata::OPTIONS])) {
6570
$config[AttributeMetadata::OPTIONS] = $attributeData[AttributeMetadata::OPTIONS];
6671
}

app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@
390390
<item name="dataType" xsi:type="string">date</item>
391391
<item name="label" xsi:type="string" translate="true">Date of Birth</item>
392392
<item name="sortOrder" xsi:type="number">170</item>
393+
<item name="timezone" xsi:type="boolean">false</item>
394+
<item name="dateFormat" xsi:type="string">MMM d, y</item>
393395
</item>
394396
</argument>
395397
</column>

app/code/Magento/Sales/view/frontend/email/order_new.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<tr class="email-summary">
3838
<td>
3939
<h1>{{trans 'Your Order <span class="no-link">#%increment_id</span>' increment_id=$order.increment_id |raw}}</h1>
40-
<p>{{trans 'Placed on <span class="no-link">%created_at</span>' created_at=$order.getCreatedAtFormatted(1) |raw}}</p>
40+
<p>{{trans 'Placed on <span class="no-link">%created_at</span>' created_at=$order.getCreatedAtFormatted(2) |raw}}</p>
4141
</td>
4242
</tr>
4343
<tr class="email-information">

app/code/Magento/Sales/view/frontend/email/order_new_guest.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"var formattedBillingAddress|raw":"Billing Address",
1010
"var order.getEmailCustomerNote()":"Email Order Note",
1111
"var order.getBillingAddress().getName()":"Guest Customer Name",
12-
"var order.getCreatedAtFormatted(1)":"Order Created At (datetime)",
12+
"var order.getCreatedAtFormatted(2)":"Order Created At (datetime)",
1313
"var order.increment_id":"Order Id",
1414
"layout handle=\"sales_email_order_items\" order=$order":"Order Items Grid",
1515
"var payment_html|raw":"Payment Details",
@@ -35,7 +35,7 @@
3535
<tr class="email-summary">
3636
<td>
3737
<h1>{{trans 'Your Order <span class="no-link">#%increment_id</span>' increment_id=$order.increment_id |raw}}</h1>
38-
<p>{{trans 'Placed on <span class="no-link">%created_at</span>' created_at=$order.getCreatedAtFormatted(1) |raw}}</p>
38+
<p>{{trans 'Placed on <span class="no-link">%created_at</span>' created_at=$order.getCreatedAtFormatted(2) |raw}}</p>
3939
</td>
4040
</tr>
4141
<tr class="email-information">

app/code/Magento/Ui/Component/Filters/Type/Date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function applyFilter()
7676
}
7777

7878
if (isset($value['to'])) {
79-
$this->applyFilterByType('lteq', $this->wrappedComponent->convertDate($value['to']));
79+
$this->applyFilterByType('lteq', $this->wrappedComponent->convertDate($value['to'], 23, 59, 59));
8080
}
8181
} else {
8282
$this->applyFilterByType('eq', $this->wrappedComponent->convertDate($value));

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,23 @@ public function getComponentName()
9292
* Convert given date to default (UTC) timezone
9393
*
9494
* @param int $date
95+
* @param int $hour
96+
* @param int $minute
97+
* @param int $second
9598
* @return \DateTime|null
9699
*/
97-
public function convertDate($date)
100+
public function convertDate($date, $hour = 0, $minute = 0, $second = 0)
98101
{
99102
try {
100-
$dateObj = $this->localeDate->date(new \DateTime($date), $this->getLocale(), false);
101-
$dateObj->setTime(0, 0, 0);
103+
$dateObj = $this->localeDate->date(
104+
new \DateTime(
105+
$date,
106+
new \DateTimeZone($this->localeDate->getConfigTimezone())
107+
),
108+
$this->getLocale(),
109+
true
110+
);
111+
$dateObj->setTime($hour, $minute, $second);
102112
//convert store date to default date in UTC timezone without DST
103113
$dateObj->setTimezone(new \DateTimeZone('UTC'));
104114
return $dateObj;

app/code/Magento/Ui/Component/Listing/Columns/Date.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public function prepareDataSource(array $dataSource)
4747
foreach ($dataSource['data']['items'] as & $item) {
4848
if (isset($item[$this->getData('name')])) {
4949
$date = $this->timezone->date(new \DateTime($item[$this->getData('name')]));
50+
if (isset($this->getConfiguration()['timezone']) && !$this->getConfiguration()['timezone']) {
51+
$date = new \DateTime($item[$this->getData('name')]);
52+
}
5053
$item[$this->getData('name')] = $date->format('Y-m-d H:i:s');
5154
}
5255
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ public function __construct(
4141
TimezoneInterface $localeDate,
4242
$data = []
4343
) {
44+
$this->localeDate = $localeDate;
4445
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
4546
$this->setType('text');
4647
$this->setExtType('textfield');
4748
if (isset($data['value'])) {
4849
$this->setValue($data['value']);
4950
}
50-
$this->localeDate = $localeDate;
5151
}
5252

5353
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function date($date = null, $locale = null, $useTimezone = true)
149149
{
150150
$locale = $locale ?: $this->_localeResolver->getLocale();
151151
$timezone = $useTimezone
152-
? $this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType)
152+
? $this->getConfigTimezone()
153153
: date_default_timezone_get();
154154

155155
if (empty($date)) {

0 commit comments

Comments
 (0)