test fixed datePicker
This commit is contained in:
parent
586ad2911c
commit
410bed4c8b
|
@ -44,12 +44,19 @@ class DatePicker extends Component {
|
||||||
this._waitingInit = 0;
|
this._waitingInit = 0;
|
||||||
this._model = value;
|
this._model = value;
|
||||||
if (value && !this.modelView) {
|
if (value && !this.modelView) {
|
||||||
let initialDateFormat = this.$translate.use() === 'es' ? 'd-m-Y' : 'Y-m-d';
|
let options = this._getOptions();
|
||||||
if (this.iniOptions.enableTime) {
|
let initialDateFormat;
|
||||||
|
if (options && options.dateFormat) {
|
||||||
|
initialDateFormat = options.dateFormat;
|
||||||
|
} else {
|
||||||
|
initialDateFormat = this.$translate.use() === 'es' ? 'd-m-Y' : 'Y-m-d';
|
||||||
|
if (options.enableTime) {
|
||||||
initialDateFormat += ' H:i:s';
|
initialDateFormat += ' H:i:s';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let format = this._formatFlat2Angular(initialDateFormat);
|
let format = this._formatFlat2Angular(initialDateFormat);
|
||||||
this._modelView = this.$filter('date')(new Date(value), format);
|
this._modelView = this.$filter('date')(new Date(this._model), format);
|
||||||
this.mdlUpdate();
|
this.mdlUpdate();
|
||||||
}
|
}
|
||||||
} else if (this._waitingInit < 4) {
|
} else if (this._waitingInit < 4) {
|
||||||
|
@ -107,13 +114,7 @@ class DatePicker extends Component {
|
||||||
return parts.join('-');
|
return parts.join('-');
|
||||||
}
|
}
|
||||||
|
|
||||||
_setModel(value) {
|
_string2BackFormat(value) {
|
||||||
let model;
|
|
||||||
if (!value) {
|
|
||||||
model = undefined;
|
|
||||||
} else if (!this.iniOptions || (this.iniOptions.dateFormat && this.iniOptions.dateFormat.startsWith('Y-m-d'))) {
|
|
||||||
model = value;
|
|
||||||
} else {
|
|
||||||
let formats = this.iniOptions.dateFormat.split(/[ZT.,/ :-]/);
|
let formats = this.iniOptions.dateFormat.split(/[ZT.,/ :-]/);
|
||||||
let aux = value.split(/[ZT.,/ :-]/);
|
let aux = value.split(/[ZT.,/ :-]/);
|
||||||
let date = {};
|
let date = {};
|
||||||
|
@ -154,7 +155,18 @@ class DatePicker extends Component {
|
||||||
hourStr += ':00';
|
hourStr += ':00';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
model = `${dateStr} ${hourStr}`.trim();
|
return `${dateStr} ${hourStr}`.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
_setModel(value) {
|
||||||
|
let model;
|
||||||
|
let options = this._getOptions();
|
||||||
|
if (!value) {
|
||||||
|
model = undefined;
|
||||||
|
} else if (!options || (options.dateFormat && options.dateFormat.startsWith('Y-m-d'))) {
|
||||||
|
model = value;
|
||||||
|
} else {
|
||||||
|
model = this._string2BackFormat(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.model !== model) {
|
if (this.model !== model) {
|
||||||
|
@ -173,7 +185,7 @@ class DatePicker extends Component {
|
||||||
this.iniOptions.locale = this.$translate.use();
|
this.iniOptions.locale = this.$translate.use();
|
||||||
|
|
||||||
if (!this.iniOptions.dateFormat)
|
if (!this.iniOptions.dateFormat)
|
||||||
this.iniOptions.dateFormat = this.iniOptions.locale === 'es' ? 'd-m-Y' : 'm-d-Y';
|
this.iniOptions.dateFormat = this.iniOptions.locale === 'es' ? 'd-m-Y' : 'Y-m-d';
|
||||||
else if (this.iniOptions.dateFormat) {
|
else if (this.iniOptions.dateFormat) {
|
||||||
let format = this.iniOptions.dateFormat.split(/[ZT.,/ :-]/);
|
let format = this.iniOptions.dateFormat.split(/[ZT.,/ :-]/);
|
||||||
if (format.length <= 1) {
|
if (format.length <= 1) {
|
||||||
|
|
|
@ -38,6 +38,7 @@ describe('Component vnDatePicker', () => {
|
||||||
|
|
||||||
it(`should split the given string into parts`, () => {
|
it(`should split the given string into parts`, () => {
|
||||||
controller.iniOptions = {dateFormat: 'd/m/Y'};
|
controller.iniOptions = {dateFormat: 'd/m/Y'};
|
||||||
|
controller._optionsChecked = true;
|
||||||
controller.model = '2017-12-23';
|
controller.model = '2017-12-23';
|
||||||
|
|
||||||
expect(controller.modelView).toBe('23-12-2017');
|
expect(controller.modelView).toBe('23-12-2017');
|
||||||
|
|
Loading…
Reference in New Issue