Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for future timestamps ... "from now"

  • Loading branch information...
commit 1f7b391782573037b4b70978a0dc14c62c56d7c9 1 parent 38c11a1
@rmm5t authored
Showing with 18 additions and 3 deletions.
  1. +6 −0 index.html
  2. +10 −3 jquery.timeago.js
  3. +2 −0  test.html
View
6 index.html
@@ -109,6 +109,12 @@
jQuery.timeago("2008-07-17"); //=> &quot;<span id="prog_string"></span>&quot;
jQuery.timeago(jQuery("abbr#some_id")); //=> &quot;<span id="prog_element"></span>&quot; // [title=&quot;2008-07-20&quot;]</pre>
+ <p class="how">
+ To support timestamps in the future, use the <tt>allowFuture</tt> setting:
+ </p>
+ <pre>
+jQuery.timeago.settings.allowFuture = true;</pre>
+
<h3>Where?</h3>
<p><a href="jquery.timeago.js">Download the &quot;stable&quot; release</a>.</p>
<p>
View
13 jquery.timeago.js
@@ -1,5 +1,5 @@
/*
- * timeago: a jQuery plugin, version: 0.3.2.99 (07/30/2008)
+ * timeago: a jQuery plugin, version: 0.4 (08/05/2008)
* @requires jQuery v1.2 or later
*
* Timeago is a jQuery plugin that makes it easy to support automatically
@@ -22,9 +22,16 @@
$.extend($.timeago, {
settings: {
- refreshMillis: 60000
+ refreshMillis: 60000,
+ allowFuture: false
},
inWords: function(distanceMillis) {
+ var suffix = " ago";
+ if (this.settings.allowFuture) {
+ if (distanceMillis < 0) suffix = " from now";
+ distanceMillis = Math.abs(distanceMillis);
+ }
+
var seconds = distanceMillis / 1000;
var minutes = seconds / 60;
var hours = minutes / 60;
@@ -43,7 +50,7 @@
years < 2 && "about a year" ||
Math.floor(years) + " years";
- return words + " ago";
+ return words + suffix;
},
parse: function(iso8601) {
var s = $.trim(iso8601);
View
2  test.html
@@ -8,6 +8,7 @@
<script src="jquery.timeago.js" type="text/javascript"></script>
<script src="test.js" type="text/javascript"></script>
<script type="text/javascript">
+ jQuery.timeago.settings.allowFuture = true;
jQuery(document).ready(function($) {
// functional tests
$('abbr[class*=timeago]').timeago();
@@ -70,6 +71,7 @@
<abbr class="todate" title="1978-12-19T02:17:00+0900"></abbr> [from +0900]<br />
<h1>Wording unit tests:</h1>
+ <abbr class="towords" title="-7200"></abbr> [-120 min]<br />
<abbr class="towords" title="-60"></abbr> [-60 sec]<br />
<abbr class="towords" title="-30"></abbr> [-30 sec]<br />
<abbr class="towords" title="-1"></abbr> [-1 sec]<br />
Please sign in to comment.
Something went wrong with that request. Please try again.