From 8451fb67004409e46becf945ee1cfd46cfe131a4 Mon Sep 17 00:00:00 2001 From: Sharif Naas Date: Tue, 2 Jun 2020 04:28:33 -0700 Subject: [PATCH] edit_history: Refactor how we handle times during modal creation. Currently, the edit history modal does not respect the time format setting (whether to show times in 12-hour or 24-hour format) when displaying message edit times (#15171). This commit refactors how fetch_and_render_message_history() handles times in order to make fixing that issue in a reasonable way easier. It will be fixed in a following commit. --- static/js/message_edit_history.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/static/js/message_edit_history.js b/static/js/message_edit_history.js index 39be4bad84..c484d80191 100644 --- a/static/js/message_edit_history.js +++ b/static/js/message_edit_history.js @@ -6,16 +6,18 @@ exports.fetch_and_render_message_history = function (message) { data: {message_id: JSON.stringify(message.id)}, success: function (data) { const content_edit_history = []; - let prev_timestamp = null; + let prev_datestamp = null; for (const [index, msg] of data.message_history.entries()) { - // Format timestamp nicely for display - const timestamp = timerender.get_full_time(msg.timestamp); + // Format times and dates nicely for display + const time = new XDate(msg.timestamp * 1000); + const datestamp = time.toDateString(); const item = { - timestamp: moment(timestamp).format("h:mm A"), - display_date: moment(timestamp).format("MMMM D, YYYY"), - show_date_row: !moment(timestamp).isSame(prev_timestamp, 'day'), + timestamp: time.toString('h:mm TT'), + display_date: time.toString("MMMM d, yyyy"), + show_date_row: datestamp !== prev_datestamp, }; + if (msg.user_id) { const person = people.get_by_user_id(msg.user_id); item.edited_by = person.full_name; @@ -43,7 +45,7 @@ exports.fetch_and_render_message_history = function (message) { content_edit_history.push(item); - prev_timestamp = timestamp; + prev_datestamp = datestamp; } $('#message-history').attr('data-message-id', message.id); $('#message-history').html(render_message_edit_history({