Skip to content

Commit

Permalink
Merge pull request #988 from nextcloud/fix/date/parsing
Browse files Browse the repository at this point in the history
Try to parse invalid date string on date-time properties
  • Loading branch information
skjnldsv authored Mar 11, 2019
2 parents 1c3923b + 7e44845 commit 76d067b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/components/Properties/PropertyDateTime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<action :actions="actions" class="property__actions" />

<!-- Real input where the picker shows -->
<datetime-picker :value="localValue.toJSDate()" :minute-step="10" :lang="lang"
<datetime-picker :value="vcardTimeLocalValue.toJSDate()" :minute-step="10" :lang="lang"
:clearable="false" :first-day-of-week="firstDay" :type="inputType"
:readonly="isReadOnly" :format="dateFormat" class="property__value"
confirm @confirm="updateValue" />
Expand Down Expand Up @@ -76,7 +76,7 @@ export default {

props: {
value: {
type: VCardTime,
type: [VCardTime, String],
default: '',
required: true
}
Expand Down Expand Up @@ -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
}
},

Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 76d067b

Please sign in to comment.