This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
56 lines (48 loc) · 1.6 KB
/
script.js
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
jQuery(function() {
function relative_time(time, basis) {
var scales = [
['second', 60],
['minute', 60],
['hour', 24],
['day', 7],
['week', 4],
['month', 12],
['year', Number.MAX_VALUE]
];
basis = basis || new Date();
var delta = Math.floor(basis / 1000) - Math.floor(time / 1000);
var future = (delta < 0);
var delta = Math.abs(delta);
if(delta < 10) {
return future ? "momentarily" : "just now";
}
for(var i=0; i < scales.length; i++) {
var scale = scales[i][0];
var factor = scales[i][1];
if(delta == 0) {
return future
? ("in less than 1 " + scale)
: ("less than 1 " + scale + "ago");
} else if(delta == 1) {
return future
? ("in 1 " + scale)
: ("1 " + scale + " ago");
} else if(delta < factor) {
return future
? ("in "+delta + " " + scale + "s")
: ("" + delta + " " + scale + "s ago");
} else {
delta = Math.floor(delta / factor);
}
}
return "outside of time";
}
function update_relative_times() {
jQuery('.stratatimetypes-relative').each(function() {
var $x = jQuery(this);
var time = Date.parse($x.attr('data-time'));
$x.text(relative_time(time));
});
}
setInterval(update_relative_times, 5000);
});