mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2024-11-23 15:57:54 -05:00
Added support for future timestamps ... "from now"
This commit is contained in:
parent
38c11a164a
commit
1f7b391782
3 changed files with 18 additions and 3 deletions
|
@ -109,6 +109,12 @@ jQuery.timeago(new Date()); //=> "<span id="prog_date"></span>&
|
|||
jQuery.timeago("2008-07-17"); //=> "<span id="prog_string"></span>"
|
||||
jQuery.timeago(jQuery("abbr#some_id")); //=> "<span id="prog_element"></span>" // [title="2008-07-20"]</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 "stable" release</a>.</p>
|
||||
<p>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 />
|
||||
|
|
Loading…
Reference in a new issue