summaryrefslogtreecommitdiffstats
path: root/src/components/Properties/PropertyDateTime.vue
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-09-11 20:27:24 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-09-11 20:27:28 +0200
commit06e5c5dafa53324f6561b7da7ccd75d742b8c144 (patch)
treeb6806ad8d441cc8255ebaa9c78fa6ab0aaed88fe /src/components/Properties/PropertyDateTime.vue
parent9eaf811cede14b2b11854635184c91cc84020dca (diff)
Fix datetime conversion and add display of date without a year
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src/components/Properties/PropertyDateTime.vue')
-rw-r--r--src/components/Properties/PropertyDateTime.vue33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/components/Properties/PropertyDateTime.vue b/src/components/Properties/PropertyDateTime.vue
index 62a8eec4..264417da 100644
--- a/src/components/Properties/PropertyDateTime.vue
+++ b/src/components/Properties/PropertyDateTime.vue
@@ -65,8 +65,11 @@ import propertyTitle from './PropertyTitle'
* and ths only common syntax between js Date, moment and VCardTime
*/
let formatDateTime = function(vcardTime, type, locale) {
+ // 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 = vcardTime.toJSON()
-
+ let datetime = ''
/**
* Make sure to display the most interesting data.
* If the Object does not have any time, do not display
@@ -74,27 +77,33 @@ let formatDateTime = function(vcardTime, type, locale) {
*/
// No hour, no minute and no second = date only
if (datetimeData.hour === null && datetimeData.minute === null && datetimeData.second === null) {
- return moment(vcardTime)
+ datetime = moment(datetimeData)
.locale(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(vcardTime)
+ datetime = moment(datetimeData)
.locale(locale)
.format('LTS')
}
// Fallback to the data ical.js provide us
- return moment(vcardTime)
- .locale(locale)
- .format(
- type === 'datetime'
- ? 'LLLL' // date & time display
- : type === 'date'
- ? 'LL' // only date
- : 'LTS' // only time
- )
+ if (datetime === '') {
+ datetime = moment(datetimeData)
+ .locale(locale)
+ .format(
+ type === 'datetime'
+ ? 'LLLL' // date & time display
+ : type === 'date'
+ ? 'LL' // only date
+ : 'LTS' // only time
+ )
+ }
+ return datetimeData.year === null
+ // replace year and remove double spaces
+ ? datetime.replace(moment(vcardTime).year(), '').replace(/\s\s+/g, ' ')
+ : datetime
}
/**