Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Now passing the distance in milliseconds to the i18n function [Closes #8

]
  • Loading branch information...
commit a003945e65943deb725d3875c57ce7e88c349151 1 parent 89a493c
@rmm5t authored
Showing with 37 additions and 1 deletion.
  1. +1 −1  jquery.timeago.js
  2. +17 −0 test/index.html
  3. +19 −0 test/test_helpers.js
View
2  jquery.timeago.js
@@ -63,7 +63,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);
}
View
17 test/index.html
@@ -174,6 +174,16 @@ <h2 id="qunit-userAgent"></h2>
<li><abbr id="testRussianSettings19" class="torussian" title="16416000"></abbr> [190 days]</li>
<li><abbr id="testRussianSettings20" class="torussian" title="31622400"></abbr> [366 days]</li>
<li><abbr id="testRussianSettings21" class="torussian" title="94608000"></abbr> [1095 days]</li>
+
+ <li><abbr id="testMillisSettings1" class="tomillis" title="-7200"></abbr> [-120 min]</li>
+ <li><abbr id="testMillisSettings2" class="tomillis" title="-60"></abbr> [-60 sec]</li>
+ <li><abbr id="testMillisSettings3" class="tomillis" title="-30"></abbr> [-30 sec]</li>
+ <li><abbr id="testMillisSettings4" class="tomillis" title="-1"></abbr> [-1 sec]</li>
+ <li><abbr id="testMillisSettings5" class="tomillis" title="0"></abbr> [0 sec]</li>
+ <li><abbr id="testMillisSettings6" class="tomillis" title="30"></abbr> [30 sec]</li>
+ <li><abbr id="testMillisSettings7" class="tomillis" title="45"></abbr> [45 sec]</li>
+ <li><abbr id="testMillisSettings8" class="tomillis" title="90"></abbr> [90 sec]</li>
+ <li><abbr id="testMillisSettings9" class="tomillis" title="120"></abbr> [120 sec]</li>
</ul>
</div>
@@ -227,6 +237,9 @@ <h2 id="qunit-userAgent"></h2>
loadRussian();
$("abbr.torussian").each(toWords);
+ loadMillis();
+ $("abbr.tomillis").each(toWords);
+
module("Valid date");
test("Text in abbr tag should be replaced", function () {
@@ -413,11 +426,13 @@ <h2 id="qunit-userAgent"></h2>
test("suffixFromNow", function () {
ok($("#testLatinSettings1").html().match(/omNow-fray$/), "Settings correctly applied");
+ ok($("#testMillisSettings1").html().match(/from now$/), "Settings correctly applied");
});
test("suffixAgo", function () {
ok($("#testLatinSettings5").html().match(/ago-hay$/), "Settings correctly applied");
ok($("#testRussianSettings5").html().match(/назад$/), "Settings correctly applied");
+ ok($("#testMillisSettings5").html().match(/ago/), "Settings correctly applied");
});
test("prefixFromNow", function () {
@@ -427,11 +442,13 @@ <h2 id="qunit-userAgent"></h2>
test("seconds", function () {
ok($("#testLatinSettings5").html().match(/^ess-lay an-thay a-hay inute-may/), "Settings correctly applied");
ok($("#testRussianSettings5").html().match(/^меньше минуты/), "Settings correctly applied");
+ ok($("#testMillisSettings5").html().match(/0 milliseconds/), "Settings correctly applied");
});
test("minute", function () {
ok($("#testLatinSettings7").html().match(/^about-hay a-hay inute-may/), "Settings correctly applied");
ok($("#testRussianSettings7").html().match(/^минуту/), "Settings correctly applied");
+ ok($("#testMillisSettings7").html().match(/45000 milliseconds/), "Settings correctly applied");
});
test("minutes", function () {
View
19 test/test_helpers.js
@@ -76,6 +76,25 @@ function loadRussian() {
})();
}
+function loadMillis() {
+ var millisSubstitution = function(number, millis) { return millis + " milliseconds"; };
+ jQuery.timeago.settings.strings = {
+ suffixAgo: "ago",
+ suffixFromNow: "from now",
+ seconds: millisSubstitution,
+ minute: millisSubstitution,
+ minutes: millisSubstitution,
+ hour: millisSubstitution,
+ hours: millisSubstitution,
+ day: millisSubstitution,
+ days: millisSubstitution,
+ month: millisSubstitution,
+ months: millisSubstitution,
+ year: millisSubstitution,
+ years: millisSubstitution
+ };
+}
+
function loadYoungOldYears() {
jQuery.extend(jQuery.timeago.settings.strings, {
years: function(value) { return (value < 21) ? "%d young years" : "%d old years"; }
Please sign in to comment.
Something went wrong with that request. Please try again.