Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'allowFuture' option or built-in Moment.js formatting #25

Open
philfreo opened this issue May 16, 2014 · 1 comment
Open

'allowFuture' option or built-in Moment.js formatting #25

philfreo opened this issue May 16, 2014 · 1 comment

Comments

@philfreo
Copy link

Great library! Structured so much nicer than jquery-timeago for single-page js apps in terms of memory usage, etc.

Feature request: support the formatting of future dates like "in 2 months".

  • Either something like the allowFuture option from jquery-timeago (although I think it should be on by default)
  • Or a built-in way to use Moment.js fromNow for the duration formatting. I'm currently doing it this way:
$.fn.timeago.Constructor.prototype.timeAgoInWords = function(timeString) {
    return moment(timeString).fromNow();
};
@dustinbolton
Copy link

My simple update to support future times as to update the TimeAgo.prototype.timeAgoInWords() function to the following:

    TimeAgo.prototype.timeAgoInWords = function(timeString) {
      var absolutTime;
      absolutTime = this.parse(timeString);
      
      if ( ( new Date().getTime() - absolutTime.getTime() ) > 0 ) {
        return "" + this.options.lang.prefixes.ago + (this.distanceOfTimeInWords(absolutTime)) + this.options.lang.suffix;
      } else {
        return this.options.lang.futurePrefix + this.options.lang.prefixes.ago + (this.distanceOfTimeInWords(absolutTime));
      }
    };

then in $.fn.timeago.defaults's "lang" key insert a line below "suffix":
futurePrefix: 'in ',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants