// Convert a UNIX timestamp to the browser's local time
-// Shamelessly swiped from https://gist.github.com/kmaida/6045266
+// See also: https://timestamp.online/article/how-to-convert-timestamp-to-datetime-in-javascript
+// In the future we could let the user select from several available formats.
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;
+ var ts = new Date(timestamp * 1000);
+ return(ts.toLocaleString());
}
+// An old version of convertTimestamp() did it the hard way.
+// It used https://gist.github.com/kmaida/6045266 as a reference.
+// check git history prior to 2022-jul-03 if you want to see it.
+
+
// Get the value of a cookie from the HTTP session
// Shamelessly swiped from https://stackoverflow.com/questions/5639346/what-is-the-shortest-function-for-reading-a-cookie-by-name-in-javascript
const getCookieValue = (name) => (
// disclosure are subject to the GNU General Public License v3.
+// A message has been selected...
+function select_message(msgnum) {
+ reading_pane = document.getElementById("ctdl-reading-pane").innerHTML = "message selected " + msgnum ;
+}
+
+
// Set up the mailbox view
function mail_display() {
target_div = document.getElementById("ctdl-main");
msgs = await(response.json());
if (response.ok) {
- box = "<table border=1 width=100%><tr>"
+ box = "<table class=\"w3-table-all\" width=100%>"
+ + "<tr class=\"w3-blue\">"
+ "<th>" + _("Subject") + "</th>"
+ "<th>" + _("Sender") + "</th>"
+ "<th>" + _("Date") + "</th>"
+ "<th>#</th>"
+ "</tr>";
-
for (var i=0; i<msgs.length; ++i) {
- box += "<tr id=\"ctdl-msgsum-" + msgs[i]["msgnum"] + "\">"
+ box += "<tr "
+ + "id=\"ctdl-msgsum-" + msgs[i]["msgnum"] + "\""
+ + "onClick=\"select_message(" + msgs[i]["msgnum"] + ")\""
+ + ">"
+ "<td>" + msgs[i]["subject"] + "</td>"
+ "<td>" + msgs[i]["author"] + " <" + msgs[i]["addr"] + "></td>"
+ "<td>" + convertTimestamp(msgs[i]["time"]) + "</td>"