From 87f74e3a4b374320d5a4bb3145e6bb7d4baea639 Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 23 Mar 2020 18:46:33 +0100 Subject: [PATCH] Pre/Suffix formatted dates with relative pronouns like "in [one day]" or "[two days] ago" --- src/main.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index b6d4c9f23..80414ac29 100644 --- a/src/main.js +++ b/src/main.js @@ -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),