timeago.js 493 B

1234567891011121314151617
  1. import Vue from 'vue'
  2. import TimeAgo from 'javascript-time-ago'
  3. import ru from 'javascript-time-ago/locale/ru'
  4. export default ({ app }, inject) => {
  5. const convertDate = (date) => {
  6. TimeAgo.addLocale(ru)
  7. const timeAgo = new TimeAgo('ru-RU')
  8. if ((date + (24*3600))* 1000 > Date.now()) {
  9. return timeAgo.format(date * 1000)
  10. } else {
  11. return timeAgo.format(date * 1000, 'twitter')
  12. }
  13. }
  14. inject('convertDate', convertDate)
  15. }