diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-09-11 11:31:09 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-09-11 11:31:09 +0200 |
commit | fae8cc1f65f07c2af7aa4ac2fea0b688f0c44c91 (patch) | |
tree | 2c57deb2a0a4096fc05beb28fa92f5de1641fd59 /src | |
parent | 31c72664f0288b0e275f370466ac44839d2ca163 (diff) |
Catch proper time or date format
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/components/Properties/PropertyDateTime.vue | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/components/Properties/PropertyDateTime.vue b/src/components/Properties/PropertyDateTime.vue index 475e6872..ccc8c171 100644 --- a/src/components/Properties/PropertyDateTime.vue +++ b/src/components/Properties/PropertyDateTime.vue @@ -140,7 +140,28 @@ export default { * and ths only common syntax between js Date, moment and VCardTime */ formatedDateTime() { - return moment(this.localValue.toJSON()) + let datetimeData = this.localValue.toJSON() + + /** + * Make sure to display the most interesting data. + * If the Object does not have any time, do not display + * the time and vice-versa. + */ + // No hour, no minute and no second = date only + if (datetimeData.hour === null && datetimeData.minute === null && datetimeData.second === null) { + return moment(datetimeData) + .locale(this.locale) + .format('LL') + + // No year, no month and no day = time only + } else if (datetimeData.year === null && datetimeData.month === null && datetimeData.day === null) { + return moment(datetimeData) + .locale(this.locale) + .format('LTS') + } + + // Fallback to the data ical.js provide us + return moment(datetimeData) .locale(this.locale) .format( this.inputType === 'datetime' @@ -202,8 +223,19 @@ export default { * Debounce and send update event to parent */ updateValue: debounce(function(e) { + let rawData = moment(e).toArray() + + /** + * Use the current year to ensure we do not lose + * the year data on v4.0 since we currently have + * no options to remove the year selection. + */ + if (this.value.year === null) { + rawData[0] = null + } + // reset the VCardTime component to the selected date/time - this.localValue.resetTo(...moment(e).toArray()) + this.localValue.resetTo(...rawData) // https://vuejs.org/v2/guide/components-custom-events.html#sync-Modifier // Use moment to convert the JsDate to Object |