Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added seconds support #44

Closed
wants to merge 2 commits into from

8 participants

@mokkabonna

I added support for seconds, but it is only triggered when refreshMillis is <= 10000, and further more provides a even more accurate wording when less <= 2000.

Also updated the documentation.

This is my first ever pull request on github, hope it's good enough. :)

@ryanbrodie

Just the addition I was looking for, great work :)

@rahilsondhi

Agreed, thanks!

@mhui

Nice job!

@nurkiewicz

+1, definitely a missing feature.

@NJAldwin

Any chances of this being pulled in anytime soon?

@NJAldwin NJAldwin referenced this pull request from a commit in NJAldwin/canary
@NJAldwin NJAldwin Add changes from rmm5t/jquery-timeago#44 to timeago for seconds accur…
…acy.
80cf09b
@NJAldwin

@rmm5t hate to bump, but this is two years old. Should I give up hope?

@rmm5t
Owner

@NJAldwin Sorry for the lack of progress on this. This feature is unlikely to happen in Timeago 1.x. I have internal plans for a Timeago 2.x which might allow for a feature as suggested here, but I honestly have no idea when or if I'll actually start on that major refactor.

@mokkabonna mokkabonna closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 23, 2011
  1. @mokkabonna

    Added support for allowing a resolution of seconds. This is triggered…

    mokkabonna authored
    … by refreshMillis <= 1000
    
    Signed-off-by: Martin Hansen <martin@martinhansen.no>
  2. @mokkabonna
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 1 deletion.
  1. +12 −0 index.html
  2. +11 −1 jquery.timeago.js
View
12 index.html
@@ -116,6 +116,18 @@
<pre>
jQuery.timeago.settings.allowFuture = true;</pre>
+
+ <p class="how">
+ To allow for a resolution of seconds, set the <tt>refreshMillis</tt> setting to <= 10000 or for even more accurate set it <= 2000:
+ </p>
+ <pre>
+jQuery.timeago.settings.refreshMillis = 1000;
+0-2 //=> "now"
+2-> //=> "xx seconds ago"
+jQuery.timeago.settings.refreshMillis = 5000;
+0-2 //=> "now"
+5-> //=> "about xx seconds ago"</pre>
+
<h3>Excusez-moi?</h3>
<p>
Yes, timeago has locale/i18n/language support. Here are some <a href="http://gist.github.com/6251">configuration examples</a>. Email <a href="http://ryan.mcgeary.org">Ryan McGeary</a> for corrections or additional languages.
View
12 jquery.timeago.js
@@ -34,6 +34,9 @@
prefixFromNow: null,
suffixAgo: "ago",
suffixFromNow: "from now",
+ secondaccurate : "now",
+ secondsaccurate : "%d seconds",
+ second: "about %d seconds",
seconds: "less than a minute",
minute: "about a minute",
minutes: "%d minutes",
@@ -60,6 +63,8 @@
distanceMillis = Math.abs(distanceMillis);
}
+
+
var seconds = distanceMillis / 1000;
var minutes = seconds / 60;
var hours = minutes / 60;
@@ -72,7 +77,12 @@
return string.replace(/%d/i, value);
}
- var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
+ suffix = seconds < 2 ? "" : suffix;
+
+ var words = seconds < 2 && this.settings.refreshMillis <= 10000 && substitute($l.secondaccurate, 1) ||
+ seconds < 60 && this.settings.refreshMillis <= 2000 && substitute($l.secondsaccurate, Math.round(seconds)) ||
+ seconds < 60 && this.settings.refreshMillis <= 10000 && substitute($l.second, Math.round(seconds)) ||
+ seconds < 45 && this.settings.refreshMillis > 10000 && substitute($l.seconds, Math.round(seconds)) ||
seconds < 90 && substitute($l.minute, 1) ||
minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
minutes < 90 && substitute($l.hour, 1) ||
Something went wrong with that request. Please try again.