Skip to content

Commit

Permalink
Merge pull request #705 from magento-fearless-kiwis/Fearless-Kiwis-MA…
Browse files Browse the repository at this point in the history
…GETWO-60765

Fearless kiwis magetwo 60765
  • Loading branch information
heyitsroberthe authored Jan 4, 2017
2 parents 804bf76 + cfe1af4 commit e6ccdcc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
21 changes: 10 additions & 11 deletions app/code/Magento/Ui/view/base/web/js/form/element/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ define([
pickerDefaultDateFormat: 'MM/dd/y', // ICU Date Format
pickerDefaultTimeFormat: 'h:mm a', // ICU Time Format

elementTmpl: 'ui/form/element/date',

/**
* Moment compatible format used for moment conversion
* of date from datePicker
* Format needed by moment timezone for conversion
*/
momentFormat: 'MM/DD/YYYY',

elementTmpl: 'ui/form/element/date',
timezoneFormat: 'YYYY-MM-DD HH:mm',

listens: {
'value': 'onValueChange',
Expand Down Expand Up @@ -141,15 +140,17 @@ define([
*/
onShiftedValueChange: function (shiftedValue) {
var value,
formattedValue;
formattedValue,
momentValue;

if (shiftedValue) {
momentValue = moment(shiftedValue, this.pickerDateTimeFormat);

if (this.options.showsTime) {
formattedValue = moment(shiftedValue).format('YYYY-MM-DD HH:mm');
formattedValue = moment(momentValue).format(this.timezoneFormat);
value = moment.tz(formattedValue, this.storeTimeZone).tz('UTC').toISOString();
} else {
value = moment(shiftedValue, this.momentFormat);
value = value.format(this.outputDateFormat);
value = momentValue.format(this.outputDateFormat);
}
} else {
value = '';
Expand All @@ -166,8 +167,6 @@ define([
*/
prepareDateTimeFormats: function () {
this.pickerDateTimeFormat = this.options.dateFormat;
this.momentFormat = this.options.dateFormat ?
utils.convertToMomentFormat(this.options.dateFormat) : this.momentFormat;

if (this.options.showsTime) {
this.pickerDateTimeFormat += ' ' + this.options.timeFormat;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

/*eslint max-nested-callbacks: 0*/

define([
'Magento_Ui/js/form/element/date',
'mageUtils',
'moment'
], function (DateElement, utils, moment) {
'use strict';

describe('Magento_Ui/js/form/element/date', function () {
var params, model;

beforeEach(function () {
params = {
dataScope: 'abstract',
options: {
showsTime: true
}
};
model = new DateElement(params);
});

it('Check prepareDateTimeFormats function', function () {
spyOn(utils, 'convertToMomentFormat').and.callThrough();
model.prepareDateTimeFormats();
expect(utils.convertToMomentFormat).toHaveBeenCalled();
});

it('Check onShiftedValueChange function', function () {
spyOn(moment, 'tz').and.callThrough();
model.onShiftedValueChange('2016-12-23 9:11 PM');
expect(moment.tz).toHaveBeenCalled();
});

});
});
2 changes: 1 addition & 1 deletion dev/tests/js/jasmine/tests/lib/mage/misc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ define([
var format, momentFormat;

format = 'M/d/yy';
momentFormat = 'MM/DD/YYYY';
momentFormat = 'M/DD/YYYY';
expect(utils.convertToMomentFormat(format)).toBe(momentFormat);
});

Expand Down
1 change: 0 additions & 1 deletion lib/web/mage/utils/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ define([

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

return newFormat;
}
Expand Down

0 comments on commit e6ccdcc

Please sign in to comment.