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
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 13 additions and 1 deletions

View File

@ -136,7 +136,19 @@ import message from './message'
import {format, formatDistance} from 'date-fns'
Vue.mixin({
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'),
error: (e, context, actions = []) => message.error(e, context, actions),
success: (s, context, actions = []) => message.success(s, context, actions),