Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to parse invalid date string on date-time properties #988

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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