Pre/Suffix formatted dates with relative pronouns like "in [one day]" or "[two days] ago"

This commit is contained in:
kolaente 2020-03-23 18:46:33 +01:00
parent 3b18b83239
commit 87f74e3a4b
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -136,7 +136,19 @@ import message from './message'
import {format, formatDistance} from 'date-fns' import {format, formatDistance} from 'date-fns'
Vue.mixin({ Vue.mixin({
methods: { methods: {
formatDateSince: date => formatDistance(date, new Date()), formatDateSince: date => {
const currentDate = new Date()
let formatted = '';
if (date > currentDate) {
formatted += 'in '
}
formatted += formatDistance(date, currentDate)
if(date < currentDate) {
formatted += ' ago'
}
return formatted;
},
formatDate: date => format(date, 'PPPPpppp'), formatDate: date => format(date, 'PPPPpppp'),
error: (e, context, actions = []) => message.error(e, context, actions), error: (e, context, actions = []) => message.error(e, context, actions),
success: (s, context, actions = []) => message.success(s, context, actions), success: (s, context, actions = []) => message.success(s, context, actions),