message view: Recipient bar date stamp shows older years.

timerender.js render_now() will always include older
years when rendering the date stamp on the recipient bar
and the date rows above messages.

Fixes #4843.
This commit is contained in:
David
2017-05-23 17:20:06 -07:00
committed by Tim Abbott
parent fcf97660db
commit 43e76816ff
2 changed files with 19 additions and 2 deletions

View File

@@ -64,6 +64,20 @@ var timerender = require('js/timerender.js');
assert.equal(expected.needs_update, actual.needs_update); assert.equal(expected.needs_update, actual.needs_update);
}()); }());
(function test_render_now_returns_year_with_year_boundary() {
var today = new XDate(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
var three_months_ago = today.clone().addMonths(-6, true);
var expected = {
time_str: 'Oct 12, 2018',
formal_time_str: 'Friday, October 12, 2018',
needs_update: false,
};
var actual = timerender.render_now(three_months_ago, today);
assert.equal(expected.time_str, actual.time_str);
assert.equal(expected.formal_time_str, actual.formal_time_str);
assert.equal(expected.needs_update, actual.needs_update);
}());
(function test_render_date_renders_time_html() { (function test_render_date_renders_time_html() {
var today = new XDate(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0) var today = new XDate(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0)
var message_time = today.clone(); var message_time = today.clone();

View File

@@ -35,15 +35,18 @@ exports.render_now = function (time, today) {
// constants. // constants.
var days_old = Math.round(start_of_other_day.diffDays(start_of_today)); var days_old = Math.round(start_of_other_day.diffDays(start_of_today));
var is_older_year =
(start_of_today.getFullYear() - start_of_other_day.getFullYear()) > 0;
if (days_old === 0) { if (days_old === 0) {
time_str = i18n.t("Today"); time_str = i18n.t("Today");
needs_update = true; needs_update = true;
} else if (days_old === 1) { } else if (days_old === 1) {
time_str = i18n.t("Yesterday"); time_str = i18n.t("Yesterday");
needs_update = true; needs_update = true;
} else if (days_old >= 365) { } else if (is_older_year) {
// For long running servers, searching backlog can get ambiguous // For long running servers, searching backlog can get ambiguous
// without a year stamp. Only show year if message is over a year old. // without a year stamp. Only show year if message is from an older year
time_str = time.toString("MMM\xa0dd,\xa0yyyy"); time_str = time.toString("MMM\xa0dd,\xa0yyyy");
needs_update = false; needs_update = false;
} else { } else {