mirror of https://github.com/zulip/zulip.git
last_seen_status_from_date: Fix incorrect last seen value.
We use day_old calculated based on day instead of hours to render last seen values. This fixes us incorrectly quoting anything 24 - 48 hours ago as Yesterday and incorrectly quoting `time` that are Yesterday but < 24 hours ago in 'x hours ago' format.
This commit is contained in:
parent
de4aeacbb1
commit
8729965548
|
@ -244,7 +244,7 @@ run_test("set_full_datetime", () => {
|
|||
});
|
||||
|
||||
run_test("last_seen_status_from_date", () => {
|
||||
// Set base_dateto to March 1 2016 12.30 AM (months are zero based)
|
||||
// Set base_date to March 1 2016 12.30 AM (months are zero based)
|
||||
let base_date = new XDate(2016, 2, 1, 0, 30);
|
||||
|
||||
function assert_same(modifier, expected_status) {
|
||||
|
@ -262,11 +262,11 @@ run_test("last_seen_status_from_date", () => {
|
|||
|
||||
assert_same((d) => d.addMinutes(-30), i18n.t("30 minutes ago"));
|
||||
|
||||
assert_same((d) => d.addHours(-1), i18n.t("An hour ago"));
|
||||
assert_same((d) => d.addHours(-1), i18n.t("Yesterday"));
|
||||
|
||||
assert_same((d) => d.addHours(-2), i18n.t("2 hours ago"));
|
||||
assert_same((d) => d.addHours(-2), i18n.t("Yesterday"));
|
||||
|
||||
assert_same((d) => d.addHours(-20), i18n.t("20 hours ago"));
|
||||
assert_same((d) => d.addHours(-20), i18n.t("Yesterday"));
|
||||
|
||||
assert_same((d) => d.addDays(-1), i18n.t("Yesterday"));
|
||||
|
||||
|
@ -280,10 +280,21 @@ run_test("last_seen_status_from_date", () => {
|
|||
|
||||
assert_same((d) => d.addYears(-3), i18n.t("Mar 01,\u00A02013"));
|
||||
|
||||
// Set base_dateto to May 1 2016 12.30 AM (months are zero based)
|
||||
// Set base_date to May 1 2016 12.30 AM (months are zero based)
|
||||
base_date = new XDate(2016, 4, 1, 0, 30);
|
||||
|
||||
assert_same((d) => d.addDays(-91), i18n.t("Jan\u00A031"));
|
||||
|
||||
// Set base_date to May 1 2016 10.30 PM (months are zero based)
|
||||
base_date = new XDate(2016, 4, 2, 23, 30);
|
||||
|
||||
assert_same((d) => d.addHours(-1), i18n.t("An hour ago"));
|
||||
|
||||
assert_same((d) => d.addHours(-2), i18n.t("2 hours ago"));
|
||||
|
||||
assert_same((d) => d.addHours(-12), i18n.t("12 hours ago"));
|
||||
|
||||
assert_same((d) => d.addHours(-24), i18n.t("Yesterday"));
|
||||
});
|
||||
|
||||
run_test("set_full_datetime", () => {
|
||||
|
|
|
@ -79,27 +79,23 @@ exports.last_seen_status_from_date = function (last_active_date, current_date) {
|
|||
if (minutes < 60) {
|
||||
return i18n.t("__minutes__ minutes ago", {minutes});
|
||||
}
|
||||
|
||||
const {days_old, is_older_year} = calculate_days_old_from_time(last_active_date, current_date);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours === 1) {
|
||||
return i18n.t("An hour ago");
|
||||
}
|
||||
if (hours < 24) {
|
||||
|
||||
if (days_old === 0) {
|
||||
if (hours === 1) {
|
||||
return i18n.t("An hour ago");
|
||||
}
|
||||
return i18n.t("__hours__ hours ago", {hours});
|
||||
}
|
||||
|
||||
const days = Math.floor(hours / 24);
|
||||
if (days === 1) {
|
||||
if (days_old === 1) {
|
||||
return i18n.t("Yesterday");
|
||||
}
|
||||
|
||||
if (days < 90) {
|
||||
return i18n.t("__days__ days ago", {days});
|
||||
} else if (
|
||||
days > 90 &&
|
||||
days < 365 &&
|
||||
current_date.getFullYear() === last_active_date.getFullYear()
|
||||
) {
|
||||
if (days_old < 90) {
|
||||
return i18n.t("__days_old__ days ago", {days_old});
|
||||
} else if (days_old > 90 && days_old < 365 && !is_older_year) {
|
||||
// Online more than 90 days ago, in the same year
|
||||
return i18n.t("__last_active_date__", {
|
||||
last_active_date: last_active_date.toString("MMM\u00A0dd"),
|
||||
|
|
Loading…
Reference in New Issue