Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
last_seen_status_from_date: Fix incorrect last seen value.
Aman Agrawal872996554882
diff --git a/frontend_tests/node_tests/timerender.js b/frontend_tests/node_tests/timerender.jsindex a2362379f35..6da3fe8a0da 100644--- a/frontend_tests/node_tests/timerender.js+++ b/frontend_tests/node_tests/timerender.js@@ -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", () => {diff --git a/static/js/timerender.js b/static/js/timerender.jsindex 5c652e5050b..9b928c748cc 100644--- a/static/js/timerender.js+++ b/static/js/timerender.js@@ -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 yearreturn i18n.t("__last_active_date__", {last_active_date: last_active_date.toString("MMM\u00A0dd"),