mirror of
https://github.com/zulip/zulip.git
synced 2025-11-22 07:21:23 +00:00
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:
committed by
Tim Abbott
parent
f7d1abaa25
commit
159064ccaa
@@ -137,16 +137,30 @@ var timerender = require('js/timerender.js');
|
|||||||
twenty_four_hour_time: false,
|
twenty_four_hour_time: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// timestamp with hour > 12
|
// timestamp with hour > 12, same year
|
||||||
var timestamp = 1555091573000; // 4/12/2019 5:52:53 PM (UTC+0)
|
var timestamp = 1555091573000; // 4/12/2019 5:52:53 PM (UTC+0)
|
||||||
var expected = 'Apr 12, 2019 05:52 PM';
|
var today = new Date(timestamp);
|
||||||
var actual = timerender.absolute_time(timestamp);
|
var expected = 'Apr 12 05:52 PM';
|
||||||
|
var actual = timerender.absolute_time(timestamp, today);
|
||||||
assert.equal(expected, actual);
|
assert.equal(expected, actual);
|
||||||
|
|
||||||
// timestamp with hour < 12
|
// timestamp with hour > 12, different year
|
||||||
|
today.setFullYear(today.getFullYear() + 1);
|
||||||
|
expected = 'Apr 12, 2019 05:52 PM';
|
||||||
|
actual = timerender.absolute_time(timestamp, today);
|
||||||
|
assert.equal(expected, actual);
|
||||||
|
|
||||||
|
// timestamp with hour < 12, same year
|
||||||
timestamp = 1495091573000; // 5/18/2017 7:12:53 AM (UTC+0)
|
timestamp = 1495091573000; // 5/18/2017 7:12:53 AM (UTC+0)
|
||||||
|
today = new Date(timestamp);
|
||||||
|
expected = 'May 18 07:12 AM';
|
||||||
|
actual = timerender.absolute_time(timestamp, today);
|
||||||
|
assert.equal(expected, actual);
|
||||||
|
|
||||||
|
// timestamp with hour < 12, different year
|
||||||
|
today.setFullYear(today.getFullYear() + 1);
|
||||||
expected = 'May 18, 2017 07:12 AM';
|
expected = 'May 18, 2017 07:12 AM';
|
||||||
actual = timerender.absolute_time(timestamp);
|
actual = timerender.absolute_time(timestamp, today);
|
||||||
assert.equal(expected, actual);
|
assert.equal(expected, actual);
|
||||||
}());
|
}());
|
||||||
|
|
||||||
@@ -155,16 +169,30 @@ var timerender = require('js/timerender.js');
|
|||||||
twenty_four_hour_time: true,
|
twenty_four_hour_time: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// timestamp with hour > 12
|
// timestamp with hour > 12, same year
|
||||||
var timestamp = 1555091573000; // 4/12/2019 17:52:53 (UTC+0)
|
var timestamp = 1555091573000; // 4/12/2019 5:52:53 PM (UTC+0)
|
||||||
var expected = 'Apr 12, 2019 17:52';
|
var today = new Date(timestamp);
|
||||||
var actual = timerender.absolute_time(timestamp);
|
var expected = 'Apr 12 17:52';
|
||||||
|
var actual = timerender.absolute_time(timestamp, today);
|
||||||
assert.equal(expected, actual);
|
assert.equal(expected, actual);
|
||||||
|
|
||||||
// timestamp with hour < 12
|
// timestamp with hour > 12, different year
|
||||||
|
today.setFullYear(today.getFullYear() + 1);
|
||||||
|
expected = 'Apr 12, 2019 17:52';
|
||||||
|
actual = timerender.absolute_time(timestamp, today);
|
||||||
|
assert.equal(expected, actual);
|
||||||
|
|
||||||
|
// timestamp with hour < 12, same year
|
||||||
timestamp = 1495091573000; // 5/18/2017 7:12:53 AM (UTC+0)
|
timestamp = 1495091573000; // 5/18/2017 7:12:53 AM (UTC+0)
|
||||||
|
today = new Date(timestamp);
|
||||||
|
expected = 'May 18 07:12';
|
||||||
|
actual = timerender.absolute_time(timestamp, today);
|
||||||
|
assert.equal(expected, actual);
|
||||||
|
|
||||||
|
// timestamp with hour < 12, different year
|
||||||
|
today.setFullYear(today.getFullYear() + 1);
|
||||||
expected = 'May 18, 2017 07:12';
|
expected = 'May 18, 2017 07:12';
|
||||||
actual = timerender.absolute_time(timestamp);
|
actual = timerender.absolute_time(timestamp, today);
|
||||||
assert.equal(expected, actual);
|
assert.equal(expected, actual);
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|||||||
@@ -235,11 +235,20 @@ exports.absolute_time = (function () {
|
|||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
return function (timestamp) {
|
return function (timestamp, today) {
|
||||||
|
if (typeof today === 'undefined') {
|
||||||
|
today = new Date();
|
||||||
|
}
|
||||||
var date = new Date(timestamp);
|
var date = new Date(timestamp);
|
||||||
|
var is_older_year = (today.getFullYear() - date.getFullYear()) > 0;
|
||||||
var H_24 = page_params.twenty_four_hour_time;
|
var H_24 = page_params.twenty_four_hour_time;
|
||||||
|
var str = MONTHS[date.getMonth()] + " " + date.getDate();
|
||||||
return MONTHS[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear() + " " + fmt_time(date, H_24);
|
// 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;
|
||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user