Displaying shorthand dates/time?


  • Plugin & Theme Dev

    How would I go about using shorter hand time ago?
    Currently: 10 hours ago
    Shorthand: 10h


  • Plugin & Theme Dev

    If it's just for one NodeBB instance you coud hard-code sth. like

    $.timeago.settings.strings = {
      prefixAgo: null,
      prefixFromNow: null,
      suffixAgo: "",
      suffixFromNow: "",
      seconds: "1m",
      minute: "1m",
      minutes: "%dm",
      hour: "1h",
      hours: "%dh",
      day: "1d",
      days: "%dd",
      month: "1mo",
      months: "%dmo",
      year: "1yr",
      years: "%dyr",
      wordSeparator: " ",
      numbers: []
    };
    

    within public/src/app.js before $('span.timeago').timeago();

    If it's for a theme/plugin you could add the same into any client-side script that triggers on page-load (like entries within plugin.json attribute scripts).
    I've taken the object from public/vendor/jquery/timeago/locales/jquery.timeago.en-short.js, there are several others that may inspire you 😉

    I've taken the method from here, maybe there exists an easier way to change the locale now since this is a 3.5a old thread... but this issue lets me assume that it's not implemented yet ^^


  • Plugin & Theme Dev

    @frissdiegurke Thanks, I'll give it a shot!


  • GNU/Linux Admin

    Yeah, the timeago library doesn't support shorthand dates, and only treats it like a separate language file, so it replaces it site-wide. Even then, the timeago string is shorthand English, so that leaves international users out in the cold too.


  • Plugin & Theme Dev

    @julian said:

    Yeah, the timeago library doesn't support shorthand dates, and only treats it like a separate language file, so it replaces it site-wide. Even then, the timeago string is shorthand English, so that leaves international users out in the cold too.

    Hardcoded in jquery.timeago.min.js 😆


  • GNU/Linux Admin

    Yeah, like @frissdiegurke mentioned, timeago uses separate locale files to override the "templates", but there's no way to use multiple templates based on the situation (shorthand for some, full for others, etc) without fundamental changes to timeago itself.


Log in to reply
 

Suggested Topics

  • 9
  • 8
  • 1
  • 10
  • 5
| |