Skip to content

Commit e6ccdcc

Browse files
Merge pull request #705 from magento-fearless-kiwis/Fearless-Kiwis-MAGETWO-60765
Fearless kiwis magetwo 60765
2 parents 804bf76 + cfe1af4 commit e6ccdcc

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

app/code/Magento/Ui/view/base/web/js/form/element/date.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ define([
5353
pickerDefaultDateFormat: 'MM/dd/y', // ICU Date Format
5454
pickerDefaultTimeFormat: 'h:mm a', // ICU Time Format
5555

56+
elementTmpl: 'ui/form/element/date',
57+
5658
/**
57-
* Moment compatible format used for moment conversion
58-
* of date from datePicker
59+
* Format needed by moment timezone for conversion
5960
*/
60-
momentFormat: 'MM/DD/YYYY',
61-
62-
elementTmpl: 'ui/form/element/date',
61+
timezoneFormat: 'YYYY-MM-DD HH:mm',
6362

6463
listens: {
6564
'value': 'onValueChange',
@@ -141,15 +140,17 @@ define([
141140
*/
142141
onShiftedValueChange: function (shiftedValue) {
143142
var value,
144-
formattedValue;
143+
formattedValue,
144+
momentValue;
145145

146146
if (shiftedValue) {
147+
momentValue = moment(shiftedValue, this.pickerDateTimeFormat);
148+
147149
if (this.options.showsTime) {
148-
formattedValue = moment(shiftedValue).format('YYYY-MM-DD HH:mm');
150+
formattedValue = moment(momentValue).format(this.timezoneFormat);
149151
value = moment.tz(formattedValue, this.storeTimeZone).tz('UTC').toISOString();
150152
} else {
151-
value = moment(shiftedValue, this.momentFormat);
152-
value = value.format(this.outputDateFormat);
153+
value = momentValue.format(this.outputDateFormat);
153154
}
154155
} else {
155156
value = '';
@@ -166,8 +167,6 @@ define([
166167
*/
167168
prepareDateTimeFormats: function () {
168169
this.pickerDateTimeFormat = this.options.dateFormat;
169-
this.momentFormat = this.options.dateFormat ?
170-
utils.convertToMomentFormat(this.options.dateFormat) : this.momentFormat;
171170

172171
if (this.options.showsTime) {
173172
this.pickerDateTimeFormat += ' ' + this.options.timeFormat;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright © 2016 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/*eslint max-nested-callbacks: 0*/
7+
8+
define([
9+
'Magento_Ui/js/form/element/date',
10+
'mageUtils',
11+
'moment'
12+
], function (DateElement, utils, moment) {
13+
'use strict';
14+
15+
describe('Magento_Ui/js/form/element/date', function () {
16+
var params, model;
17+
18+
beforeEach(function () {
19+
params = {
20+
dataScope: 'abstract',
21+
options: {
22+
showsTime: true
23+
}
24+
};
25+
model = new DateElement(params);
26+
});
27+
28+
it('Check prepareDateTimeFormats function', function () {
29+
spyOn(utils, 'convertToMomentFormat').and.callThrough();
30+
model.prepareDateTimeFormats();
31+
expect(utils.convertToMomentFormat).toHaveBeenCalled();
32+
});
33+
34+
it('Check onShiftedValueChange function', function () {
35+
spyOn(moment, 'tz').and.callThrough();
36+
model.onShiftedValueChange('2016-12-23 9:11 PM');
37+
expect(moment.tz).toHaveBeenCalled();
38+
});
39+
40+
});
41+
});

dev/tests/js/jasmine/tests/lib/mage/misc.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ define([
1515
var format, momentFormat;
1616

1717
format = 'M/d/yy';
18-
momentFormat = 'MM/DD/YYYY';
18+
momentFormat = 'M/DD/YYYY';
1919
expect(utils.convertToMomentFormat(format)).toBe(momentFormat);
2020
});
2121

lib/web/mage/utils/misc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ define([
220220

221221
newFormat = format.replace(/yy|y/gi, 'YYYY'); // replace the year
222222
newFormat = newFormat.replace(/dd|d/g, 'DD'); // replace the date
223-
newFormat = newFormat.replace(/mm|m/gi, 'MM'); //replace the month
224223

225224
return newFormat;
226225
}

0 commit comments

Comments
 (0)