Skip to content

Commit

Permalink
Added support for milliseconds in ISO 8601 timestamps [Closes rmm5t#13]
Browse files Browse the repository at this point in the history
  • Loading branch information
rmm5t committed Jun 21, 2010
1 parent 3109ef5 commit e8e3072
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions jquery.timeago.js
Expand Up @@ -84,6 +84,7 @@
},
parse: function(iso8601) {
var s = $.trim(iso8601);
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
Expand Down
6 changes: 6 additions & 0 deletions test/index.html
Expand Up @@ -70,6 +70,7 @@ <h2>Other formats</h2>
<p>Date only (time element): <time class="timeago" datetime="2008-02-26">(you shouldn't see this)</time>.</p>
<p>Date only (friendly tooltip): <abbr id="testTooltip" class="timeago" title="2008-02-26">February 26th</abbr>.</p>
<p>Date only (default tooltip): <abbr id="defaultTooltip" class="timeago" title="2008-02-26"> </abbr>.</p>
<p>Timestsamp (with millis): <abbr class="timeago" title="1978-12-18T17:17:00.021Z">(you shouldn't see this)</abbr>.</p>

<h2>Errors</h2>

Expand All @@ -89,6 +90,7 @@ <h2>Parsing</h2>
<li><abbr id="testParsing5" class="todate" title="1978-12-19T02:17:00+09:00"></abbr> [from +09:00]</li>
<li><abbr id="testParsing6" class="todate" title="1978-12-19T02:17:00+0900"></abbr> [from +0900]</li>
<li><abbr id="testParsing7" class="todate" title="1978-12-18 17:17:00"></abbr> [from blank TZ]</li>
<li><abbr id="testParsing8" class="todate" title="1978-12-18 17:17:00.021Z"></abbr> [from Z with milliseonds]</li>
</ul>

<h2>Wording</h2>
Expand Down Expand Up @@ -311,6 +313,10 @@ <h2>Settings</h2>
ok(($("#testParsing7").html().match(/Mon, 18 Dec 1978 \d\d:17:00 GMT/)), "Correctly parsed, assumed local time");
});

test("From Z with milliseconds", function () {
ok(($("#testParsing8").html().match(correctMatch)), "Correctly parsed");
});

module("Wording");

test("-120 min", function () {
Expand Down

0 comments on commit e8e3072

Please sign in to comment.