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'
|
||||
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),
|
||||
|
|
Loading…
Reference in a new issue