|
@@ -1,5 +1,12 @@
|
|
|
$(function() {
|
|
|
moment.lang($('html').attr('lang'))
|
|
|
+
|
|
|
+ if (lang_time_units === undefined) {
|
|
|
+ var units_formats = "smhd";
|
|
|
+ } else {
|
|
|
+ var units_formats = lang_time_units;
|
|
|
+ }
|
|
|
+
|
|
|
var moment_now = moment();
|
|
|
var time_format = moment_now.lang()._longDateFormat.LT;
|
|
|
|
|
@@ -11,11 +18,9 @@ $(function() {
|
|
|
var timestamp = $(this).data('timestamp');
|
|
|
var rel_moment = moment(timestamp);
|
|
|
|
|
|
- if (moment_now.diff(rel_moment, 'days') <= 7) {
|
|
|
- moments[timestamp] = {
|
|
|
- rel_moment: rel_moment,
|
|
|
- original: $(this).text()
|
|
|
- }
|
|
|
+ moments[timestamp] = {
|
|
|
+ rel_moment: rel_moment,
|
|
|
+ original: $(this).text()
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -25,16 +30,35 @@ $(function() {
|
|
|
function update_times() {
|
|
|
$('.time-ago').each(function() {
|
|
|
var timestamp = $(this).data('timestamp');
|
|
|
- if (moments[timestamp] != undefined) {
|
|
|
- if (moment_now.diff(moments[timestamp].rel_moment, 'hours') <= 6 && moment_now.diff(moments[timestamp].rel_moment, 'hours') >= -6) {
|
|
|
- $(this).text(moments[timestamp].rel_moment.fromNow());
|
|
|
- } else if (moment_now.diff(moments[timestamp].rel_moment, 'days') < 1 && moment_now.diff(moments[timestamp].rel_moment, 'days') > -1) {
|
|
|
- $(this).text(moments[timestamp].rel_moment.calendar());
|
|
|
- } else if (moment_now.diff(moments[timestamp].rel_moment, 'days') < 7 && moment_now.diff(moments[timestamp].rel_moment, 'days') > -7) {
|
|
|
- $(this).text(moments[timestamp].rel_moment.format("dddd, " + time_format));
|
|
|
- } else {
|
|
|
- $(this).text(moments[timestamp].original);
|
|
|
- }
|
|
|
+
|
|
|
+ if (moment_now.diff(moments[timestamp].rel_moment, 'minutes') <= 6 && moment_now.diff(moments[timestamp].rel_moment, 'hours') >= -6) {
|
|
|
+ $(this).text(moments[timestamp].rel_moment.fromNow());
|
|
|
+ } else if (moment_now.diff(moments[timestamp].rel_moment, 'days') < 1 && moment_now.diff(moments[timestamp].rel_moment, 'days') > -1) {
|
|
|
+ $(this).text(moments[timestamp].rel_moment.calendar());
|
|
|
+ } else if (moment_now.diff(moments[timestamp].rel_moment, 'days') < 7 && moment_now.diff(moments[timestamp].rel_moment, 'days') > -7) {
|
|
|
+ $(this).text(moments[timestamp].rel_moment.format("dddd, " + time_format));
|
|
|
+ } else {
|
|
|
+ $(this).text(moments[timestamp].original);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.time-ago-compact').each(function() {
|
|
|
+ var timestamp = $(this).data('timestamp');
|
|
|
+ var diff_seconds = moment_now.diff(moments[timestamp].rel_moment, 'seconds');
|
|
|
+
|
|
|
+ if (diff_seconds < 60) {
|
|
|
+ $(this).text(diff_seconds + units_formats[0]);
|
|
|
+ } else if (diff_seconds < (60 * 56)) {
|
|
|
+ var diff_minutes = Math.floor(diff_seconds / 60);
|
|
|
+ $(this).text(diff_minutes + units_formats[1]);
|
|
|
+ } else if (diff_seconds <= (3600 * 23)) {
|
|
|
+ var diff_hours = Math.floor(diff_seconds / 3600);
|
|
|
+ $(this).text(diff_hours + units_formats[2]);
|
|
|
+ } else if (true | diff_seconds < (3600 * 24 * 15)) {
|
|
|
+ var diff_days = Math.floor(diff_seconds / (3600 * 24));
|
|
|
+ $(this).text(diff_days + units_formats[3]);
|
|
|
+ } else {
|
|
|
+ $(this).text(moments[timestamp].original);
|
|
|
}
|
|
|
});
|
|
|
}
|