Pre/Suffix formatted dates with relative pronouns like "in [one day]" or "[two days] ago"
This commit is contained in:
parent
3b18b83239
commit
87f74e3a4b
1 changed files with 13 additions and 1 deletions
14
src/main.js
14
src/main.js
|
@ -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),
|
||||||
|
|
Loading…
Reference in a new issue