Skip to content

Commit

Permalink
update jquery.timeago to 0.9.3 to resolve NaN date issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarianski committed Aug 4, 2011
1 parent 7e6e44a commit 33777c4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -27,6 +27,8 @@ Unreleased

- Fix layout issue on community search results page (LP #820523)

- Update jquery.timeago to 0.9.3 to resolve NaN date issues (LP #821014)

3.68 (2011-07-14)
-----------------

Expand Down
28 changes: 17 additions & 11 deletions karl/views/static/jquery-plugins/jquery.timeago.js
@@ -1,5 +1,5 @@
/*
* timeago: a jQuery plugin, version: 0.9 (2010-06-21)
* timeago: a jQuery plugin, version: 0.9.3 (2011-01-21)
* @requires jQuery v1.2.3 or later
*
* Timeago is a jQuery plugin that makes it easy to support automatically
Expand All @@ -11,13 +11,17 @@
* Licensed under the MIT:
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright (c) 2008-2010, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
* Copyright (c) 2008-2011, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
*/
(function($) {
$.timeago = function(timestamp) {
if (timestamp instanceof Date) return inWords(timestamp);
else if (typeof timestamp == "string") return inWords($.timeago.parse(timestamp));
else return inWords($.timeago.datetime(timestamp));
if (timestamp instanceof Date) {
return inWords(timestamp);
} else if (typeof timestamp === "string") {
return inWords($.timeago.parse(timestamp));
} else {
return inWords($.timeago.datetime(timestamp));
}
};
var $t = $.timeago;

Expand Down Expand Up @@ -63,7 +67,7 @@
var years = days / 365;

function substitute(stringOrFunction, number) {
var string = $.isFunction(stringOrFunction) ? stringOrFunction(number) : stringOrFunction;
var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
var value = ($l.numbers && $l.numbers[number]) || number;
return string.replace(/%d/i, value);
}
Expand All @@ -84,15 +88,15 @@
},
parse: function(iso8601) {
var s = $.trim(iso8601);
s = s.replace(/\.\d\d\d/,""); // remove milliseconds
s = s.replace(/\.\d\d\d+/,""); // remove milliseconds
s = s.replace(/-/,"/").replace(/-/,"/");
s = s.replace(/T/," ").replace(/Z/," UTC");
s = s.replace(/([\+-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
return new Date(s);
},
datetime: function(elem) {
// jQuery's `is()` doesn't play well with HTML5 in IE
var isTime = $(elem).get(0).tagName.toLowerCase() == "time"; // $(elem).is("time");
var isTime = $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
var iso8601 = isTime ? $(elem).attr("datetime") : $(elem).attr("title");
return $t.parse(iso8601);
}
Expand Down Expand Up @@ -122,7 +126,9 @@
if (!element.data("timeago")) {
element.data("timeago", { datetime: $t.datetime(element) });
var text = $.trim(element.text());
if (text.length > 0) element.attr("title", text);
if (text.length > 0) {
element.attr("title", text);
}
}
return element.data("timeago");
}
Expand All @@ -138,4 +144,4 @@
// fix for IE6 suckage
document.createElement("abbr");
document.createElement("time");
})(jQuery);
}(jQuery));
2 changes: 1 addition & 1 deletion karl/views/static/min/karl-ui.min.js

Large diffs are not rendered by default.

0 comments on commit 33777c4

Please sign in to comment.