diff --git a/jquery.timeago.js b/jquery.timeago.js index 50b7a6e..2936d8f 100644 --- a/jquery.timeago.js +++ b/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); } diff --git a/test/index.html b/test/index.html index 0148a98..dfee89d 100644 --- a/test/index.html +++ b/test/index.html @@ -174,6 +174,16 @@
  • [190 days]
  • [366 days]
  • [1095 days]
  • + +
  • [-120 min]
  • +
  • [-60 sec]
  • +
  • [-30 sec]
  • +
  • [-1 sec]
  • +
  • [0 sec]
  • +
  • [30 sec]
  • +
  • [45 sec]
  • +
  • [90 sec]
  • +
  • [120 sec]
  • @@ -227,6 +237,9 @@ 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 @@ 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 @@ 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 () { diff --git a/test/test_helpers.js b/test/test_helpers.js index 6add4fd..6a345e2 100644 --- a/test/test_helpers.js +++ b/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"; }