From: Art Cancro Date: Mon, 3 Jan 2022 20:13:44 +0000 (-0500) Subject: Message date/time is now sent to the browser in unix timestamp format X-Git-Tag: v944~18 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=9bc6e22ca790e9ea0917a95a156306345f59e1e8;p=citadel.git Message date/time is now sent to the browser in unix timestamp format and converted to a displayable date/time in the local timezone by the browser. --- diff --git a/webcit-ng/forum_view.c b/webcit-ng/forum_view.c index b66db14aa..846c417b5 100644 --- a/webcit-ng/forum_view.c +++ b/webcit-ng/forum_view.c @@ -58,12 +58,7 @@ void json_render_one_message(struct http_transaction *h, struct ctdlsession *c, safestrncpy(emailaddr, &buf[5], sizeof emailaddr); } else if (!strncasecmp(buf, "time=", 5)) { - time_t tt; - struct tm tm; - tt = atol(&buf[5]); - localtime_r(&tt, &tm); - strftime(datetime, sizeof datetime, "%c", &tm); - JsonObjectAppend(j, NewJsonPlainString(HKEY("time"), datetime, -1)); + JsonObjectAppend(j, NewJsonNumber(HKEY("time"), atol(&buf[5]))); } else if (!strncasecmp(buf, "locl=", 5)) { message_originated_locally = 1; diff --git a/webcit-ng/static/js/util.js b/webcit-ng/static/js/util.js index 5e80a8986..201247450 100644 --- a/webcit-ng/static/js/util.js +++ b/webcit-ng/static/js/util.js @@ -82,3 +82,35 @@ function escapeJS(text) { return '\\' + a ; }); } + + +// Convert a UNIX timestamp to the browser's local time +// Shamelessly swiped from https://gist.github.com/kmaida/6045266 +function convertTimestamp(timestamp) { + var d = new Date(timestamp * 1000), // Convert the passed timestamp to milliseconds + yyyy = d.getFullYear(), + mm = ('0' + (d.getMonth() + 1)).slice(-2), // Months are zero based. Add leading 0. + dd = ('0' + d.getDate()).slice(-2), // Add leading 0. + hh = d.getHours(), + h = hh, + min = ('0' + d.getMinutes()).slice(-2), // Add leading 0. + ampm = 'AM', + time; + + if (hh > 12) { + h = hh - 12; + ampm = 'PM'; + } + else if (hh === 12) { + h = 12; + ampm = 'PM'; + } + else if (hh == 0) { + h = 12; + } + + // ie: 2013-02-18, 8:35 AM + time = yyyy + '-' + mm + '-' + dd + ', ' + h + ':' + min + ' ' + ampm; + + return time; +} diff --git a/webcit-ng/static/js/view_forum.js b/webcit-ng/static/js/view_forum.js index 09aec3d31..77793dd2b 100644 --- a/webcit-ng/static/js/view_forum.js +++ b/webcit-ng/static/js/view_forum.js @@ -174,7 +174,7 @@ function forum_render_one(msg, existing_div) { + msg.from + "" // end username + "" - + msg.time + + convertTimestamp(msg.time) + "" // end msgdate + "" // end header info on left side + "" // begin buttons on right side @@ -256,11 +256,11 @@ function open_reply_box(parent_div, is_quoted, references, msgid) { + "
" // begin content + "
" // begin header + "" // begin header info on left side - + "" // FIXME link to user profile - + "FIXME my name" - + "" // end username + + "" + + current_user // user = me ! + + "" + "" - + "FIXME now time" + + "FIXME now time " + convertTimestamp(1637714172) + "" // end msgdate + "" // end header info on left side + "" // begin buttons on right side