uploads: Only display year uploaded if previous year.

Modified timerender.js absolute_time() to include the year
in the returned string when the supplied timestamp is in
an older year. This included adding an optional second
argument to specify the current date to facilitate unit
tests.

Fixes #5737.
This commit is contained in:
David Coleman
2017-07-25 22:20:31 -07:00
committed by Tim Abbott
parent f7d1abaa25
commit 159064ccaa
2 changed files with 51 additions and 14 deletions

View File

@@ -235,11 +235,20 @@ exports.absolute_time = (function () {
return str;
};
return function (timestamp) {
return function (timestamp, today) {
if (typeof today === 'undefined') {
today = new Date();
}
var date = new Date(timestamp);
var is_older_year = (today.getFullYear() - date.getFullYear()) > 0;
var H_24 = page_params.twenty_four_hour_time;
return MONTHS[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear() + " " + fmt_time(date, H_24);
var str = MONTHS[date.getMonth()] + " " + date.getDate();
// include year if message date is from a previous year
if (is_older_year) {
str += ", " + date.getFullYear();
}
str += " " + fmt_time(date, H_24);
return str;
};
}());