forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.timeago-tests.ts
66 lines (52 loc) · 2.25 KB
/
jquery.timeago-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/// <reference path="../jquery/jquery.d.ts"/>
/// <reference path="jquery.timeago.d.ts"/>
// Basic usage
var jQueryElement: JQuery = jQuery("abbr.timeago").timeago();
// Programmatic use
var result1: string = jQuery.timeago(new Date());
var result2: string = jQuery.timeago("2008-07-17");
var result3: string = jQuery.timeago(jQuery("abbr#some_id"));
var result4: string = jQuery.timeago(document.getElementById("some_id"));
// Helpers
var string1: string = jQuery.timeago.inWords(new Date());
var string2: string = jQuery.timeago.inWords(123456);
var date1: Date = jQuery.timeago.parse("2008-07-17T09:24:17Z");
var date2: Date = jQuery.timeago.datetime(jQuery("abbr#some_id"));
var date3: Date = jQuery.timeago.datetime(document.getElementById("some_id"));
var isTime1: bool = jQuery.timeago.isTime(jQuery("abbr#some_id"));
var isTime2: bool = jQuery.timeago.isTime(document.getElementById("some_id"));
// Settings
jQuery.timeago.settings.refreshMillis = 6000;
jQuery.timeago.settings.allowFuture = true;
jQuery.timeago.settings.strings.wordSeparator = "#";
// Russian locale
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 лет"); }
};