-
Notifications
You must be signed in to change notification settings - Fork 1
/
momentary.js
38 lines (31 loc) · 1.14 KB
/
momentary.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
$(document).ready(function() {
//Call the function relativeTime every one minute (6000 milliseconds)
setInterval(relativeTime, 60000);
//<span class="relativetime" title="2015-09-17 18:25:08">1 min ago</span>
//Taking the timestamp from the title attribute of all the elements with the class 'relativetime' and pass it to the function 'timeSince'.
function relativeTime() {
$('.relativetime').each(function () {
$(this).text((timeSince($(this).attr('title').replace(" ", "T"))));
});
}
//Global Variables
var DURATION_IN_SECONDS = {
epochs: ['year', 'month', 'day', 'hour', 'minute'],
year: 31536000,
month: 2592000,
day: 86400,
hour: 3600,
minute: 60
};
//Calculating the duration
function getDuration(seconds) {
var epoch, interval;
for (var i = 0; i < DURATION_IN_SECONDS.epochs.length; i++) {
epoch = DURATION_IN_SECONDS.epochs[i];
interval = Math.floor(seconds / DURATION_IN_SECONDS[epoch]);
if (interval >= 1) {
return {interval: interval, epoch: epoch};
}
}
};
});