Skip to main content
Sign in
Snippets Groups Projects
Commit 6614360a authored by Susan Wright's avatar Susan Wright Committed by GitHub
Browse files

Merge pull request #453 from magento-fearless-kiwis/FearlessKiwis-MAGETWO-55867-New-Incorrect-Time

Fixed issue:
 - MAGETWO-55867 Date and time are shown incorrectly for staging updates
parents 9ed631da 7c80c5c7
Branches
No related tags found
No related merge requests found
...@@ -32,6 +32,8 @@ class Date extends AbstractDataType ...@@ -32,6 +32,8 @@ class Date extends AbstractDataType
protected $wrappedComponent; protected $wrappedComponent;
/** /**
* Constructor
*
* @param ContextInterface $context * @param ContextInterface $context
* @param TimezoneInterface $localeDate * @param TimezoneInterface $localeDate
* @param ResolverInterface $localeResolver * @param ResolverInterface $localeResolver
...@@ -58,23 +60,15 @@ class Date extends AbstractDataType ...@@ -58,23 +60,15 @@ class Date extends AbstractDataType
public function prepare() public function prepare()
{ {
$config = $this->getData('config'); $config = $this->getData('config');
if (!isset($config['storeTimeZone'])) {
if (!isset($config['timeOffset'])) { $storeTimeZone = $this->localeDate->getConfigTimezone();
$config['timeOffset'] = (new \DateTime( $config['storeTimeZone'] = $storeTimeZone;
'now',
new \DateTimeZone(
$this->localeDate->getConfigTimezone()
)
))->getOffset();
} }
// Set date format pattern by current locale // Set date format pattern by current locale
$localeDateFormat = $this->localeDate->getDateFormat(); $localeDateFormat = $this->localeDate->getDateFormat();
$config['options']['dateFormat'] = $localeDateFormat; $config['options']['dateFormat'] = $localeDateFormat;
$config['outputDateFormat'] = $localeDateFormat; $config['outputDateFormat'] = $localeDateFormat;
$this->setData('config', $config); $this->setData('config', $config);
parent::prepare(); parent::prepare();
} }
... ...
......
...@@ -6,54 +6,48 @@ ...@@ -6,54 +6,48 @@
namespace Magento\Ui\Test\Unit\Component\Form\Element\DataType; namespace Magento\Ui\Test\Unit\Component\Form\Element\DataType;
use Magento\Ui\Component\Form\Element\DataType\Date; use Magento\Ui\Component\Form\Element\DataType\Date;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\View\Element\UiComponent\Context;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\View\Element\UiComponent\Processor;
class DateTest extends \PHPUnit_Framework_TestCase class DateTest extends \PHPUnit_Framework_TestCase
{ {
/** /** @var \PHPUnit_Framework_MockObject_MockObject */
* @var \Magento\Framework\View\Element\UiComponent\ContextInterface|\PHPUnit_Framework_MockObject_MockObject private $contextMock;
*/
private $context;
/** /** @var \PHPUnit_Framework_MockObject_MockObject */
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject private $localeDateMock;
*/
private $localeDate;
/** /** @var \PHPUnit_Framework_MockObject_MockObject */
* @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject private $localeResolverMock;
*/
private $localeResolver;
/** /** @var \Magento\Ui\Component\Form\Element\DataType\Date */
* @var Date private $date;
*/
private $model;
public function setUp()
{
$processorMock = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
->disableOriginalConstructor()
->getMock();
$this->context = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class) /** @var \PHPUnit_Framework_MockObject_MockObject */
->getMockForAbstractClass(); private $processorMock;
$this->context->expects($this->any())
->method('getProcessor')
->willReturn($processorMock);
$this->localeDate = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class) /** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
->getMockForAbstractClass(); private $objectManagerHelper;
$this->localeResolver = $this->getMockBuilder(\Magento\Framework\Locale\ResolverInterface::class) public function setUp()
->getMockForAbstractClass(); {
$this->contextMock = $this->getMock(Context::class, [], [], '', false);
$this->localeDateMock = $this->getMock(TimezoneInterface::class, [], [], '', false);
$this->localeResolverMock = $this->getMock(ResolverInterface::class, [], [], '', false);
$this->objectManagerHelper = new ObjectManager($this);
$this->processorMock = $this->getMock(Processor::class, [], [], '', false);
$this->contextMock->expects($this->any())->method('getProcessor')->willReturn($this->processorMock);
} }
public function testPrepareWithTimeOffset() public function testPrepareWithTimeOffset()
{ {
$this->model = new Date( $this->date = new Date(
$this->context, $this->contextMock,
$this->localeDate, $this->localeDateMock,
$this->localeResolver, $this->localeResolverMock,
[], [],
[ [
'config' => [ 'config' => [
...@@ -64,13 +58,13 @@ class DateTest extends \PHPUnit_Framework_TestCase ...@@ -64,13 +58,13 @@ class DateTest extends \PHPUnit_Framework_TestCase
$localeDateFormat = 'dd/MM/y'; $localeDateFormat = 'dd/MM/y';
$this->localeDate->expects($this->once()) $this->localeDateMock->expects($this->once())
->method('getDateFormat') ->method('getDateFormat')
->willReturn($localeDateFormat); ->willReturn($localeDateFormat);
$this->model->prepare(); $this->date->prepare();
$config = $this->model->getConfig(); $config = $this->date->getConfig();
$this->assertTrue(is_array($config)); $this->assertTrue(is_array($config));
$this->assertArrayHasKey('options', $config); $this->assertArrayHasKey('options', $config);
...@@ -85,10 +79,10 @@ class DateTest extends \PHPUnit_Framework_TestCase ...@@ -85,10 +79,10 @@ class DateTest extends \PHPUnit_Framework_TestCase
{ {
$defaultDateFormat = 'MM/dd/y'; $defaultDateFormat = 'MM/dd/y';
$this->model = new Date( $this->date = new Date(
$this->context, $this->contextMock,
$this->localeDate, $this->localeDateMock,
$this->localeResolver, $this->localeResolverMock,
[], [],
[ [
'config' => [ 'config' => [
...@@ -102,20 +96,18 @@ class DateTest extends \PHPUnit_Framework_TestCase ...@@ -102,20 +96,18 @@ class DateTest extends \PHPUnit_Framework_TestCase
$localeDateFormat = 'dd/MM/y'; $localeDateFormat = 'dd/MM/y';
$this->localeDate->expects($this->once()) $this->localeDateMock->expects($this->once())
->method('getDateFormat') ->method('getDateFormat')
->willReturn($localeDateFormat); ->willReturn($localeDateFormat);
$this->localeDate->expects($this->once()) $this->localeDateMock->expects($this->any())
->method('getConfigTimezone') ->method('getConfigTimezone')
->willReturn('America/Los_Angeles'); ->willReturn('America/Los_Angeles');
$this->model->prepare(); $this->date->prepare();
$config = $this->model->getConfig(); $config = $this->date->getConfig();
$this->assertTrue(is_array($config)); $this->assertTrue(is_array($config));
$this->assertArrayHasKey('timeOffset', $config);
$this->assertArrayHasKey('options', $config); $this->assertArrayHasKey('options', $config);
$this->assertArrayHasKey('dateFormat', $config['options']); $this->assertArrayHasKey('dateFormat', $config['options']);
$this->assertEquals($localeDateFormat, $config['options']['dateFormat']); $this->assertEquals($localeDateFormat, $config['options']['dateFormat']);
...@@ -123,4 +115,23 @@ class DateTest extends \PHPUnit_Framework_TestCase ...@@ -123,4 +115,23 @@ class DateTest extends \PHPUnit_Framework_TestCase
$this->assertArrayHasKey('outputDateFormat', $config); $this->assertArrayHasKey('outputDateFormat', $config);
$this->assertEquals($localeDateFormat, $config['outputDateFormat']); $this->assertEquals($localeDateFormat, $config['outputDateFormat']);
} }
/**
* This tests ensures that userTimeZone is properly saved in the configuration
*/
public function testPrepare()
{
$this->date = $this->objectManagerHelper->getObject(
Date::class,
[
'context' => $this->contextMock,
'localeDate' => $this->localeDateMock,
'localeResolver' => $this->localeResolverMock
]
);
$this->localeDateMock->expects($this->any())->method('getConfigTimezone')->willReturn('America/Chicago');
$this->date->prepare();
$configArray = $this->date->getData('config');
$this->assertEquals('America/Chicago', $configArray['storeTimeZone']);
}
} }
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
define([ define([
'moment', 'moment',
'mageUtils', 'mageUtils',
'./abstract' './abstract',
'moment-timezone-with-data'
], function (moment, utils, Abstract) { ], function (moment, utils, Abstract) {
'use strict'; 'use strict';
...@@ -13,7 +14,7 @@ define([ ...@@ -13,7 +14,7 @@ define([
defaults: { defaults: {
options: {}, options: {},
timeOffset: 0, storeTimeZone: 'UTC',
validationParams: { validationParams: {
dateFormat: '${ $.outputDateFormat }' dateFormat: '${ $.outputDateFormat }'
...@@ -61,7 +62,7 @@ define([ ...@@ -61,7 +62,7 @@ define([
/** /**
* Date/time value shifted to corresponding timezone * Date/time value shifted to corresponding timezone
* according to this.timeOffset property. This value * according to this.storeTimeZone property. This value
* will be sent to the server. * will be sent to the server.
* *
* @type {String} * @type {String}
...@@ -109,7 +110,7 @@ define([ ...@@ -109,7 +110,7 @@ define([
if (value) { if (value) {
if (this.options.showsTime) { if (this.options.showsTime) {
shiftedValue = moment.utc(value).add(this.timeOffset, 'seconds'); shiftedValue = moment.tz(value, 'UTC').tz(this.storeTimeZone);
} else { } else {
dateFormat = this.shiftedValue() ? this.outputDateFormat : this.inputDateFormat; dateFormat = this.shiftedValue() ? this.outputDateFormat : this.inputDateFormat;
...@@ -133,12 +134,13 @@ define([ ...@@ -133,12 +134,13 @@ define([
* @param {String} shiftedValue * @param {String} shiftedValue
*/ */
onShiftedValueChange: function (shiftedValue) { onShiftedValueChange: function (shiftedValue) {
var value; var value,
formattedValue;
if (shiftedValue) { if (shiftedValue) {
if (this.options.showsTime) { if (this.options.showsTime) {
value = moment.utc(shiftedValue, this.pickerDateTimeFormat); formattedValue = moment(shiftedValue).format('YYYY-MM-DD HH:mm');
value = value.subtract(this.timeOffset, 'seconds').toISOString(); value = moment.tz(formattedValue, this.storeTimeZone).tz('UTC').toISOString();
} else { } else {
value = moment(shiftedValue, this.pickerDateTimeFormat); value = moment(shiftedValue, this.pickerDateTimeFormat);
value = value.format(this.outputDateFormat); value = value.format(this.outputDateFormat);
... ...
......
...@@ -39,6 +39,7 @@ define([ ...@@ -39,6 +39,7 @@ define([
'EEE': 'ddd', 'EEE': 'ddd',
'e': 'd', 'e': 'd',
'yyyy': 'YYYY', 'yyyy': 'YYYY',
'yy': 'YY',
'y': 'YYYY', 'y': 'YYYY',
'a': 'A' 'a': 'A'
}; };
... ...
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment