Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

refactor: Remove current_date arg from relative_time_string_from_date.

Shubham Padiad5de26ff3bf6
diff --git a/web/src/recent_view_ui.js b/web/src/recent_view_ui.js
index 67be119d7b7..373df5f378f 100644
--- a/web/src/recent_view_ui.js
+++ b/web/src/recent_view_ui.js
@@ -480,9 +480,7 @@ function format_conversation(conversation_data) {
context.full_last_msg_date_time = timerender.get_full_datetime_clarification(time);
context.conversation_key = recent_view_util.get_key_from_message(last_msg);
context.unread_count = message_to_conversation_unread_count(last_msg);
- context.last_msg_time = timerender.relative_time_string_from_date({
- date: time,
- });
+ context.last_msg_time = timerender.relative_time_string_from_date(time);
context.is_private = last_msg.type === "private";
let all_senders;
let senders;
diff --git a/web/src/settings_exports.ts b/web/src/settings_exports.ts
index 390f194c15c..053c42db244 100644
--- a/web/src/settings_exports.ts
+++ b/web/src/settings_exports.ts
@@ -59,15 +59,15 @@ export function populate_exports_table(exports: RealmExport[]): void {
let deleted_timestamp = null;
if (data.failed_timestamp !== null) {
- failed_timestamp = timerender.relative_time_string_from_date({
- date: new Date(data.failed_timestamp * 1000),
- });
+ failed_timestamp = timerender.relative_time_string_from_date(
+ new Date(data.failed_timestamp * 1000),
+ );
}
if (data.deleted_timestamp !== null) {
- deleted_timestamp = timerender.relative_time_string_from_date({
- date: new Date(data.deleted_timestamp * 1000),
- });
+ deleted_timestamp = timerender.relative_time_string_from_date(
+ new Date(data.deleted_timestamp * 1000),
+ );
}
return render_admin_export_list({
@@ -75,9 +75,9 @@ export function populate_exports_table(exports: RealmExport[]): void {
id: data.id,
acting_user: people.get_full_name(data.acting_user_id),
// Convert seconds -> milliseconds
- event_time: timerender.relative_time_string_from_date({
- date: new Date(data.export_time * 1000),
- }),
+ event_time: timerender.relative_time_string_from_date(
+ new Date(data.export_time * 1000),
+ ),
url: data.export_url,
time_failed: failed_timestamp,
pending: data.pending,
diff --git a/web/src/timerender.ts b/web/src/timerender.ts
index 1f46bc20e89..7448bec859f 100644
--- a/web/src/timerender.ts
+++ b/web/src/timerender.ts
@@ -213,15 +213,8 @@ export function render_now(time: Date, today = new Date()): TimeRender {
}
// Relative time rendering for use in most screens like Recent conversations.
-//
-// Current date is passed as an argument for unit testing
-export function relative_time_string_from_date({
- date,
- current_date = new Date(),
-}: {
- date: Date;
- current_date?: Date;
-}): string {
+export function relative_time_string_from_date(date: Date): string {
+ const current_date = new Date();
const minutes = differenceInMinutes(current_date, date);
if (minutes <= 2) {
return $t({defaultMessage: "Just now"});
diff --git a/web/tests/timerender.test.js b/web/tests/timerender.test.js
index ab174652f61..32795e7d81e 100644
--- a/web/tests/timerender.test.js
+++ b/web/tests/timerender.test.js
@@ -531,13 +531,11 @@ run_test("last_seen_status_from_date", () => {
run_test("relative_time_string_from_date", () => {
// Set base_date to March 1 2016 12.30 AM (months are zero based)
let base_date = new Date(2016, 2, 1, 0, 30);
+ MockDate.set(base_date.getTime());
function assert_same(duration, expected_status) {
const past_date = add(base_date, duration);
- const actual_status = timerender.relative_time_string_from_date({
- date: past_date,
- current_date: base_date,
- });
+ const actual_status = timerender.relative_time_string_from_date(past_date);
assert.equal(actual_status, expected_status);
}
@@ -571,11 +569,13 @@ run_test("relative_time_string_from_date", () => {
// Set base_date to May 1 2016 12.30 AM (months are zero based)
base_date = new Date(2016, 4, 1, 0, 30);
+ MockDate.set(base_date.getTime());
assert_same({days: -91}, "Jan 31");
// Set base_date to May 1 2016 10.30 PM (months are zero based)
base_date = new Date(2016, 4, 2, 23, 30);
+ MockDate.set(base_date.getTime());
assert_same({hours: -1}, $t({defaultMessage: "An hour ago"}));
@@ -584,6 +584,8 @@ run_test("relative_time_string_from_date", () => {
assert_same({hours: -12}, $t({defaultMessage: "12 hours ago"}));
assert_same({hours: -24}, $t({defaultMessage: "Yesterday"}));
+
+ MockDate.reset();
});
run_test("set_full_datetime", () => {