egoist / vue-timeago

A timeago component for Vue.
https://vue-timeago.egoist.sh
MIT License
729 stars 104 forks source link

"just now" instead of "less than a minute ago" #93

Closed soichih closed 5 years ago

soichih commented 5 years ago

In the previous version, I was seeing "just now" if the date is less than 60 seconds old. On the latest version, it is now showing "less than a minute ago". I prefer "just now" as it was shorter and it fits the table I am using to display the date.

Is there a way to show "just now" (maybe by setting some custom option with date-fns)?

jwheatp commented 5 years ago

I could not find a better solution than :

// main.js
import VueTimeago from "vue-timeago";
import toNow from 'date-fns/distance_in_words_to_now'

Vue.use(VueTimeago, {
  name: "Timeago",
  converter: (date, locale, converterOptions) => {
    const { includeSeconds, addSuffix = true } = converterOptions
    return toNow(date, {
      locale,
      includeSeconds,
      addSuffix
    }).replace("less than a minute ago", "just now") // here
  }
});

If anyone has better 🙏

egoist commented 5 years ago

You can manipulate it like what @jwheatp did here, or if you believe just now is a better default, you can contribute to date-fns.