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.

timerender: Change relative_time_string_from_date signature.

Daniil Fadeev72fa8b568c4f
diff --git a/web/src/recent_view_ui.js b/web/src/recent_view_ui.js
index da9d6bbc85d..07b12ae2cb2 100644
--- a/web/src/recent_view_ui.js
+++ b/web/src/recent_view_ui.js
@@ -373,7 +373,9 @@ function format_conversation(conversation_data) {
context.full_last_msg_date_time = timerender.get_full_datetime_clarification(time);
context.conversation_key = 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(time);
+ context.last_msg_time = timerender.relative_time_string_from_date({
+ date: time,
+ });
context.is_private = last_msg.type === "private";
let all_senders;
let senders;
diff --git a/web/src/settings_exports.js b/web/src/settings_exports.js
index 0c5fe785f87..1780d9aead0 100644
--- a/web/src/settings_exports.js
+++ b/web/src/settings_exports.js
@@ -47,15 +47,15 @@ export function populate_exports_table(exports) {
let deleted_timestamp = data.deleted_timestamp;
if (failed_timestamp !== null) {
- failed_timestamp = timerender.relative_time_string_from_date(
- new Date(failed_timestamp * 1000),
- );
+ failed_timestamp = timerender.relative_time_string_from_date({
+ date: new Date(failed_timestamp * 1000),
+ });
}
if (deleted_timestamp !== null) {
- deleted_timestamp = timerender.relative_time_string_from_date(
- new Date(deleted_timestamp * 1000),
- );
+ deleted_timestamp = timerender.relative_time_string_from_date({
+ date: new Date(deleted_timestamp * 1000),
+ });
}
return render_admin_export_list({
@@ -63,9 +63,9 @@ export function populate_exports_table(exports) {
id: data.id,
acting_user: people.get_full_name(data.acting_user_id),
// Convert seconds -> milliseconds
- event_time: timerender.relative_time_string_from_date(
- new Date(data.export_time * 1000),
- ),
+ event_time: timerender.relative_time_string_from_date({
+ 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 c8d2569b6ca..c39e0a55283 100644
--- a/web/src/timerender.ts
+++ b/web/src/timerender.ts
@@ -190,11 +190,14 @@ 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(
- last_active_date: Date,
+export function relative_time_string_from_date({
+ date,
current_date = new Date(),
-): string {
- const minutes = differenceInMinutes(current_date, last_active_date);
+}: {
+ date: Date;
+ current_date?: Date;
+}): string {
+ const minutes = differenceInMinutes(current_date, date);
if (minutes <= 2) {
return $t({defaultMessage: "Just now"});
}
@@ -202,7 +205,7 @@ export function relative_time_string_from_date(
return $t({defaultMessage: "{minutes} minutes ago"}, {minutes});
}
- const days_old = differenceInCalendarDays(current_date, last_active_date);
+ const days_old = differenceInCalendarDays(current_date, date);
const hours = Math.floor(minutes / 60);
if (hours < 24) {
@@ -221,12 +224,12 @@ export function relative_time_string_from_date(
} else if (
days_old > 90 &&
days_old < 365 &&
- last_active_date.getFullYear() === current_date.getFullYear()
+ date.getFullYear() === current_date.getFullYear()
) {
// Online more than 90 days ago, in the same year
- return get_localized_date_or_time_for_format(last_active_date, "dayofyear");
+ return get_localized_date_or_time_for_format(date, "dayofyear");
}
- return get_localized_date_or_time_for_format(last_active_date, "dayofyear_year");
+ return get_localized_date_or_time_for_format(date, "dayofyear_year");
}
// Relative time logic variant use in the buddy list, where every
diff --git a/web/tests/timerender.test.js b/web/tests/timerender.test.js
index 3eed481ac56..52b722b40f5 100644
--- a/web/tests/timerender.test.js
+++ b/web/tests/timerender.test.js
@@ -529,7 +529,10 @@ run_test("relative_time_string_from_date", () => {
function assert_same(duration, expected_status) {
const past_date = add(base_date, duration);
- const actual_status = timerender.relative_time_string_from_date(past_date, base_date);
+ const actual_status = timerender.relative_time_string_from_date({
+ date: past_date,
+ current_date: base_date,
+ });
assert.equal(actual_status, expected_status);
}