jquery-timeago/test/test_helpers.js

77 lines
2.4 KiB
JavaScript
Raw Normal View History

2009-08-15 10:26:12 -04:00
var zeropad = function (num) {
return ((num < 10) ? '0' : '') + num;
};
var iso8601 = function (date) {
return date.getUTCFullYear()
+ "-" + zeropad(date.getUTCMonth()+1)
+ "-" + zeropad(date.getUTCDate())
+ "T" + zeropad(date.getUTCHours())
+ ":" + zeropad(date.getUTCMinutes())
+ ":" + zeropad(date.getUTCSeconds()) + "Z";
};
jQuery(document).ready(function($) {
$('abbr.loaded').attr("title", iso8601(new Date()));
$('abbr.modified').attr("title", iso8601(new Date(document.lastModified)));
});
function loadPigLatin() {
jQuery.timeago.settings.strings = {
suffixAgo: "ago-hay",
suffixFromNow: "omNow-fray",
seconds: "ess-lay an-thay a-hay inute-may",
minute: "about-hay a-hay inute-may",
minutes: "%d inutes-may",
hour: "about-hay an-hay hour-hay",
hours: "about-hay %d hours-hay",
day: "a-hay ay-day",
days: "%d ays-day",
month: "about-hay a-hay onth-may",
months: "%d onths-may",
year: "about-hay a-hay ear-yay",
years: "%d years-yay"
};
}
function loadRussian() {
(function() {
function numpf(n, f, s, t) {
// f - 1, 21, 31, ...
// s - 2-4, 22-24, 32-34 ...
// t - 5-20, 25-30, ...
var n10 = n % 10;
if ( (n10 == 1) && ( (n == 1) || (n > 20) ) ) {
return f;
} else if ( (n10 > 1) && (n10 < 5) && ( (n > 20) || (n < 10) ) ) {
return s;
} else {
return t;
}
}
jQuery.timeago.settings.strings = {
prefixAgo: null,
prefixFromNow: "через",
suffixAgo: "назад",
suffixFromNow: null,
seconds: "меньше минуты",
minute: "минуту",
minutes: function(value) { return numpf(value, "%d минута", "%d минуты", "%d минут"); },
hour: "час",
hours: function(value) { return numpf(value, "%d час", "%d часа", "%d часов"); },
day: "день",
days: function(value) { return numpf(value, "%d день", "%d дня", "%d дней"); },
month: "месяц",
months: function(value) { return numpf(value, "%d месяц", "%d месяца", "%d месяцев"); },
year: "год",
years: function(value) { return numpf(value, "%d год", "%d года", "%d лет"); }
};
})();
}
function loadYoungOldYears() {
jQuery.extend(jQuery.timeago.settings.strings, {
years: function(value) { return (value < 21) ? "%d young years" : "%d old years"; }
});
}