test fixed datePicker

This commit is contained in:
Daniel Herrero 2018-01-10 14:08:56 +01:00
parent 586ad2911c
commit 410bed4c8b
2 changed files with 60 additions and 47 deletions

View File

@ -44,12 +44,19 @@ class DatePicker extends Component {
this._waitingInit = 0;
this._model = value;
if (value && !this.modelView) {
let initialDateFormat = this.$translate.use() === 'es' ? 'd-m-Y' : 'Y-m-d';
if (this.iniOptions.enableTime) {
let options = this._getOptions();
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';
}
}
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();
}
} else if (this._waitingInit < 4) {
@ -107,13 +114,7 @@ class DatePicker extends Component {
return parts.join('-');
}
_setModel(value) {
let model;
if (!value) {
model = undefined;
} else if (!this.iniOptions || (this.iniOptions.dateFormat && this.iniOptions.dateFormat.startsWith('Y-m-d'))) {
model = value;
} else {
_string2BackFormat(value) {
let formats = this.iniOptions.dateFormat.split(/[ZT.,/ :-]/);
let aux = value.split(/[ZT.,/ :-]/);
let date = {};
@ -154,7 +155,18 @@ class DatePicker extends Component {
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) {
@ -173,7 +185,7 @@ class DatePicker extends Component {
this.iniOptions.locale = this.$translate.use();
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) {
let format = this.iniOptions.dateFormat.split(/[ZT.,/ :-]/);
if (format.length <= 1) {

View File

@ -38,6 +38,7 @@ describe('Component vnDatePicker', () => {
it(`should split the given string into parts`, () => {
controller.iniOptions = {dateFormat: 'd/m/Y'};
controller._optionsChecked = true;
controller.model = '2017-12-23';
expect(controller.modelView).toBe('23-12-2017');