From 7e4484518f6d6d16688fa62542c418f6d2687afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Mon, 11 Mar 2019 12:17:06 +0100 Subject: [PATCH] Try to parse invalid date string on date-time properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- src/components/Properties/PropertyDateTime.vue | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/Properties/PropertyDateTime.vue b/src/components/Properties/PropertyDateTime.vue index bfabf3979..670557dc5 100644 --- a/src/components/Properties/PropertyDateTime.vue +++ b/src/components/Properties/PropertyDateTime.vue @@ -47,7 +47,7 @@ - @@ -76,7 +76,7 @@ export default { props: { value: { - type: VCardTime, + type: [VCardTime, String], default: '', required: true } @@ -115,6 +115,15 @@ export default { let isLast = this.isLastProperty ? 1 : 0 // length is always one & add one space at the end return hasTitle + 1 + isLast + }, + + // make sure the property is valid + vcardTimeLocalValue() { + if (typeof this.localValue === 'string') { + // eslint-disable-next-line new-cap + return new VCardTime.fromDateAndOrTimeString(this.localValue) + } + return this.localValue } }, @@ -196,7 +205,7 @@ export default { // this is the only possibility for us to ensure // no data is lost. e.g. if no second are set // the second will be null and not 0 - let datetimeData = this.localValue.toJSON() + let datetimeData = this.vcardTimeLocalValue.toJSON() let datetime = '' // FUN FACT: JS date starts month at zero! @@ -236,7 +245,7 @@ export default { return datetimeData.year === null // replace year and remove double spaces - ? datetime.replace(moment(this.localValue).year(), '').replace(/\s\s+/g, ' ') + ? datetime.replace(moment(this.vcardTimeLocalValue).year(), '').replace(/\s\s+/g, ' ') : datetime } }