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

Test for native iso8601 date support #167

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions jquery.timeago.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
} }
}; };
var $t = $.timeago; var $t = $.timeago;
var iso8601Support = Date.prototype.toISOString;


$.extend($.timeago, { $.extend($.timeago, {
settings: { settings: {
Expand Down Expand Up @@ -103,10 +104,12 @@
}, },
parse: function(iso8601) { parse: function(iso8601) {
var s = $.trim(iso8601); var s = $.trim(iso8601);
s = s.replace(/\.\d+/,""); // remove milliseconds if (!iso8601Support) {
s = s.replace(/-/,"/").replace(/-/,"/"); s = s.replace(/\.\d+/,""); // remove milliseconds
s = s.replace(/T/," ").replace(/Z/," UTC"); s = s.replace(/-/,"/").replace(/-/,"/");
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400 s = s.replace(/T/," ").replace(/Z/," UTC");
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
}
s = s.replace(/([\+\-]\d\d)$/," $100"); // +09 -> +0900 s = s.replace(/([\+\-]\d\d)$/," $100"); // +09 -> +0900
return new Date(s); return new Date(s);
}, },
Expand Down