Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
refactor: Remove today arg from absolute_time.
Shubham Padiaa43a898e12d6
diff --git a/web/src/timerender.ts b/web/src/timerender.tsindex ea7a386ebec..ce2e0781fed 100644--- a/web/src/timerender.ts+++ b/web/src/timerender.ts@@ -465,7 +465,8 @@ export function format_time_modern(time: number | Date, today = new Date()): str// this is for rendering absolute time based off the preferences for twenty-four// hour time in the format of "%mmm %d, %h:%m %p".-export function absolute_time(timestamp: number, today = new Date()): string {+export function absolute_time(timestamp: number): string {+ const today = new Date();const date = new Date(timestamp);const is_older_year = today.getFullYear() - date.getFullYear() > 0;diff --git a/web/tests/timerender.test.js b/web/tests/timerender.test.jsindex a8293ea2218..f1fc092f2c3 100644--- a/web/tests/timerender.test.js+++ b/web/tests/timerender.test.js@@ -394,29 +394,35 @@ run_test("absolute_time_12_hour", () => {let timestamp = date_2019.getTime();let today = date_2019;+ MockDate.set(today.getTime());let expected = "Apr 12, 5:52 PM";- let actual = timerender.absolute_time(timestamp, today);+ let actual = timerender.absolute_time(timestamp);assert.equal(actual, expected);// timestamp with hour > 12, different yearlet next_year = add(today, {years: 1});+ MockDate.set(next_year.getTime());expected = "Apr 12, 2019, 5:52 PM";- actual = timerender.absolute_time(timestamp, next_year);+ actual = timerender.absolute_time(timestamp);assert.equal(actual, expected);// timestamp with hour < 12, same yeartimestamp = date_2017.getTime();today = date_2017;+ MockDate.set(today.getTime());expected = "May 18, 7:12 AM";- actual = timerender.absolute_time(timestamp, today);+ actual = timerender.absolute_time(timestamp);assert.equal(actual, expected);// timestamp with hour < 12, different yearnext_year = add(today, {years: 1});+ MockDate.set(next_year.getTime());expected = "May 18, 2017, 7:12 AM";- actual = timerender.absolute_time(timestamp, next_year);+ actual = timerender.absolute_time(timestamp);assert.equal(actual, expected);++ MockDate.reset();});run_test("absolute_time_24_hour", () => {@@ -424,28 +430,33 @@ run_test("absolute_time_24_hour", () => {// date with hour > 12, same yearlet today = date_2019;+ MockDate.set(today.getTime());let expected = "Apr 12, 17:52";- let actual = timerender.absolute_time(date_2019.getTime(), today);+ let actual = timerender.absolute_time(date_2019.getTime());assert.equal(actual, expected);// date with hour > 12, different yearlet next_year = add(today, {years: 1});-+ MockDate.set(next_year.getTime());expected = "Apr 12, 2019, 17:52";- actual = timerender.absolute_time(date_2019.getTime(), next_year);+ actual = timerender.absolute_time(date_2019.getTime());assert.equal(actual, expected);// timestamp with hour < 12, same yeartoday = date_2017;+ MockDate.set(today.getTime());expected = "May 18, 07:12";- actual = timerender.absolute_time(date_2017.getTime(), today);+ actual = timerender.absolute_time(date_2017.getTime());assert.equal(actual, expected);// timestamp with hour < 12, different yearnext_year = add(today, {years: 1});+ MockDate.set(next_year.getTime());expected = "May 18, 2017, 07:12";- actual = timerender.absolute_time(date_2017.getTime(), next_year);+ actual = timerender.absolute_time(date_2017.getTime());assert.equal(actual, expected);++ MockDate.reset();});run_test("get_full_datetime", () => {