(function () {
- var lang = {
- months : "styczeń_luty_marzec_kwiecień_maj_czerwiec_lipiec_sierpień_wrzesień_październik_listopad_grudzień".split("_"),
- monthsShort : "sty_lut_mar_kwi_maj_cze_lip_sie_wrz_paź_lis_gru".split("_"),
- weekdays : "niedziela_poniedziałek_wtorek_środa_czwartek_piątek_sobota".split("_"),
- weekdaysShort : "nie_pon_wt_śr_czw_pt_sb".split("_"),
- longDateFormat : {
- L : "DD-MM-YYYY",
- LL : "D MMMM YYYY",
- LLL : "D MMMM YYYY HH:mm",
- LLLL : "dddd, D MMMM YYYY HH:mm"
- },
- relativeTime : {
- future : "za %s",
- past : "%s temu",
- s : "kilka sekund",
- m : "minutę",
- mm : "%d minut",
- h : "godzinę",
- hh : "%d godzin",
- d : "1 dzień",
- dd : "%d dni",
- M : "miesiąc",
- MM : "%d miesięcy",
- y : "rok",
- yy : "%d lat"
- },
- ordinal : function (number) {
- return '.';
- }
+ var singular = function (ws, a, b) {
+ return ws ? a : b;
+ },
+ plural = function (n, a, b) {
+ return ((n % 10 < 5) && (n % 10 > 1) && (~~(n / 10) !== 1)) ? n + ' ' + a : n + ' ' + b;
+ },
+ singularf = function (a, b) {
+ return function (n, ws) {
+ return singular(ws, a, b);
};
+ },
+ pluralf = function (a, b) {
+ return function (n) {
+ return plural(n, a, b);
+ };
+ },
+
+ lang = {
+ months : "styczeń_luty_marzec_kwiecień_maj_czerwiec_lipiec_sierpień_wrzesień_październik_listopad_grudzień".split("_"),
+ monthsShort : "sty_lut_mar_kwi_maj_cze_lip_sie_wrz_paź_lis_gru".split("_"),
+ weekdays : "niedziela_poniedziałek_wtorek_środa_czwartek_piątek_sobota".split("_"),
+ weekdaysShort : "nie_pon_wt_śr_czw_pt_sb".split("_"),
+ longDateFormat : {
+ L : "DD-MM-YYYY",
+ LL : "D MMMM YYYY",
+ LLL : "D MMMM YYYY HH:mm",
+ LLLL : "dddd, D MMMM YYYY HH:mm"
+ },
+ relativeTime : {
+ future : "za %s",
+ past : "%s temu",
+ s : "kilka sekund",
+ m : singularf('minuta', 'minutę'),
+ mm : pluralf('minuty', 'minut'),
+ h : singularf('godzina', 'godzinę'),
+ hh : pluralf('godziny', 'godzin'),
+ d : "1 dzień",
+ dd : '%d dni',
+ M : "miesiąc",
+ MM : pluralf('miesiące', 'miesięcy'),
+ y : "rok",
+ yy : pluralf('lata', 'lat')
+ },
+ ordinal : function (number) {
+ return '.';
+ }
+ };
// Node
if (typeof module !== 'undefined') {
moment.lang('pl');
var start = moment([2007, 1, 28]);
equal(start.from(moment([2007, 1, 28]).add({s:44}), true), "kilka sekund", "44 seconds = a few seconds");
- equal(start.from(moment([2007, 1, 28]).add({s:45}), true), "minutę", "45 seconds = a minute");
- equal(start.from(moment([2007, 1, 28]).add({s:89}), true), "minutę", "89 seconds = a minute");
- equal(start.from(moment([2007, 1, 28]).add({s:90}), true), "2 minut", "90 seconds = 2 minutes");
- equal(start.from(moment([2007, 1, 28]).add({m:44}), true), "44 minut", "44 minutes = 44 minutes");
- equal(start.from(moment([2007, 1, 28]).add({m:45}), true), "godzinę", "45 minutes = an hour");
- equal(start.from(moment([2007, 1, 28]).add({m:89}), true), "godzinę", "89 minutes = an hour");
- equal(start.from(moment([2007, 1, 28]).add({m:90}), true), "2 godzin", "90 minutes = 2 hours");
+ equal(start.from(moment([2007, 1, 28]).add({s:45}), true), "minuta", "45 seconds = a minute");
+ equal(start.from(moment([2007, 1, 28]).add({s:89}), true), "minuta", "89 seconds = a minute");
+ equal(start.from(moment([2007, 1, 28]).add({s:90}), true), "2 minuty", "90 seconds = 2 minutes");
+ equal(start.from(moment([2007, 1, 28]).add({m:44}), true), "44 minuty", "44 minutes = 44 minutes");
+ equal(start.from(moment([2007, 1, 28]).add({m:45}), true), "godzina", "45 minutes = an hour");
+ equal(start.from(moment([2007, 1, 28]).add({m:89}), true), "godzina", "89 minutes = an hour");
+ equal(start.from(moment([2007, 1, 28]).add({m:90}), true), "2 godziny", "90 minutes = 2 hours");
equal(start.from(moment([2007, 1, 28]).add({h:5}), true), "5 godzin", "5 hours = 5 hours");
equal(start.from(moment([2007, 1, 28]).add({h:21}), true), "21 godzin", "21 hours = 21 hours");
equal(start.from(moment([2007, 1, 28]).add({h:22}), true), "1 dzień", "22 hours = a day");
equal(start.from(moment([2007, 1, 28]).add({d:26}), true), "miesiąc", "26 days = a month");
equal(start.from(moment([2007, 1, 28]).add({d:30}), true), "miesiąc", "30 days = a month");
equal(start.from(moment([2007, 1, 28]).add({d:45}), true), "miesiąc", "45 days = a month");
- equal(start.from(moment([2007, 1, 28]).add({d:46}), true), "2 miesiÄ\99cy", "46 days = 2 months");
- equal(start.from(moment([2007, 1, 28]).add({d:74}), true), "2 miesiÄ\99cy", "75 days = 2 months");
- equal(start.from(moment([2007, 1, 28]).add({d:76}), true), "3 miesiÄ\99cy", "76 days = 3 months");
+ equal(start.from(moment([2007, 1, 28]).add({d:46}), true), "2 miesiÄ\85ce", "46 days = 2 months");
+ equal(start.from(moment([2007, 1, 28]).add({d:74}), true), "2 miesiÄ\85ce", "75 days = 2 months");
+ equal(start.from(moment([2007, 1, 28]).add({d:76}), true), "3 miesiÄ\85ce", "76 days = 3 months");
equal(start.from(moment([2007, 1, 28]).add({M:1}), true), "miesiąc", "1 month = a month");
equal(start.from(moment([2007, 1, 28]).add({M:5}), true), "5 miesięcy", "5 months = 5 months");
equal(start.from(moment([2007, 1, 28]).add({d:344}), true), "11 miesięcy", "344 days = 11 months");
equal(start.from(moment([2007, 1, 28]).add({d:345}), true), "rok", "345 days = a year");
equal(start.from(moment([2007, 1, 28]).add({d:547}), true), "rok", "547 days = a year");
- equal(start.from(moment([2007, 1, 28]).add({d:548}), true), "2 lat", "548 days = 2 years");
+ equal(start.from(moment([2007, 1, 28]).add({d:548}), true), "2 lata", "548 days = 2 years");
equal(start.from(moment([2007, 1, 28]).add({y:1}), true), "rok", "1 year = a year");
equal(start.from(moment([2007, 1, 28]).add({y:5}), true), "5 lat", "5 years = 5 years");
});
});
-test("fromNow", 2, function() {
+test("fromNow", 3, function() {
moment.lang('pl');
equal(moment().add({s:30}).fromNow(), "za kilka sekund", "in a few seconds");
+ equal(moment().add({h:1}).fromNow(), "za godzinę", "in an hour");
equal(moment().add({d:5}).fromNow(), "za 5 dni", "in 5 days");
});
});
// helper function for _date.from() and _date.fromNow()
- function substituteTimeAgo(string, number) {
- return moment.relativeTime[string].replace(/%d/i, number || 1);
+ function substituteTimeAgo(string, number, withoutSuffix) {
+ var rt = moment.relativeTime[string];
+ return (typeof rt === 'function') ? rt(number || 1, !!withoutSuffix) : rt.replace(/%d/i, number || 1);
}
- function relativeTime(milliseconds) {
+ function relativeTime(milliseconds, withoutSuffix) {
var seconds = Math.abs(milliseconds) / 1000,
minutes = seconds / 60,
hours = minutes / 60,
days = hours / 24,
years = days / 365;
- return seconds < 45 && substituteTimeAgo('s', round(seconds)) ||
- round(minutes) === 1 && substituteTimeAgo('m') ||
- minutes < 45 && substituteTimeAgo('mm', round(minutes)) ||
- round(hours) === 1 && substituteTimeAgo('h') ||
- hours < 22 && substituteTimeAgo('hh', round(hours)) ||
- round(days) === 1 && substituteTimeAgo('d') ||
- days <= 25 && substituteTimeAgo('dd', round(days)) ||
- days <= 45 && substituteTimeAgo('M') ||
- days < 345 && substituteTimeAgo('MM', round(days / 30)) ||
- round(years) === 1 && substituteTimeAgo('y') ||
- substituteTimeAgo('yy', round(years));
+ return seconds < 45 && substituteTimeAgo('s', round(seconds), withoutSuffix) ||
+ round(minutes) === 1 && substituteTimeAgo('m', 1, withoutSuffix) ||
+ minutes < 45 && substituteTimeAgo('mm', round(minutes), withoutSuffix) ||
+ round(hours) === 1 && substituteTimeAgo('h', 1, withoutSuffix) ||
+ hours < 22 && substituteTimeAgo('hh', round(hours), withoutSuffix) ||
+ round(days) === 1 && substituteTimeAgo('d', 1, withoutSuffix) ||
+ days <= 25 && substituteTimeAgo('dd', round(days), withoutSuffix) ||
+ days <= 45 && substituteTimeAgo('M', 1, withoutSuffix) ||
+ days < 345 && substituteTimeAgo('MM', round(days / 30), withoutSuffix) ||
+ round(years) === 1 && substituteTimeAgo('y', 1, withoutSuffix) ||
+ substituteTimeAgo('yy', round(years), withoutSuffix);
}
// shortcut for prototype
from : function (time, withoutSuffix) {
var difference = this.diff(time),
rel = moment.relativeTime,
- output = relativeTime(difference);
+ output = relativeTime(difference, withoutSuffix);
return withoutSuffix ? output : (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output);
},