From 5c44539de144ee2a4b1a2b80e15d3d80a09933b5 Mon Sep 17 00:00:00 2001 From: Jiewei Qian Date: Mon, 25 Jun 2018 16:47:45 +0800 Subject: [PATCH] DatePicker: guards common but incorrect usage (#11673) --- packages/date-picker/src/picker.vue | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/date-picker/src/picker.vue b/packages/date-picker/src/picker.vue index ac66148bd..c62615311 100644 --- a/packages/date-picker/src/picker.vue +++ b/packages/date-picker/src/picker.vue @@ -508,12 +508,21 @@ export default { }, parsedValue() { - const isParsed = isDateObject(this.value) || (Array.isArray(this.value) && this.value.every(isDateObject)); - if (this.valueFormat && !isParsed) { - return parseAsFormatAndType(this.value, this.valueFormat, this.type, this.rangeSeparator) || this.value; - } else { + if (!this.value) return this.value; // component value is not set + if (this.type === 'time-select') return this.value; // time-select does not require parsing, this might change in next major version + + const valueIsDateObject = isDateObject(this.value) || (Array.isArray(this.value) && this.value.every(isDateObject)); + if (valueIsDateObject) { return this.value; } + + if (this.valueFormat) { + return parseAsFormatAndType(this.value, this.valueFormat, this.type, this.rangeSeparator) || this.value; + } + + // NOTE: deal with common but incorrect usage, should remove in next major version + // user might provide string / timestamp without value-format, coerce them into date (or array of date) + return Array.isArray(this.value) ? this.value.map(val => new Date(val)) : new Date(this.value); }, _elFormItemSize() {