Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions portality/static/js/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,56 @@ $.extend(true, doaj, {
return new Date(year, month, day, hours, minutes, seconds, milliseconds);
},

formatFullDateTime : function(input){
try {
// Fast validation
if (typeof input !== "string" || input.length < 20) {
console.error("formatTimestamp: Invalid input →", input);
return input;
}

// Normalize microseconds → milliseconds (no regex)
let normalized = input;
const dotIndex = input.indexOf(".");
if (dotIndex !== -1) {
const zIndex = input.indexOf("Z", dotIndex);
if (zIndex !== -1) {
normalized = input.slice(0, dotIndex + 4) + "Z";
}
}

const date = new Date(normalized);

// Invalid date check (fast NaN check)
if (date.getTime() !== date.getTime()) {
console.error("formatTimestamp: Invalid date →", input);
return input;
}

// Extract parts
const y = date.getUTCFullYear();
const m = date.getUTCMonth() + 1;
const d = date.getUTCDate();
const h = date.getUTCHours();
const min = date.getUTCMinutes();
const s = date.getUTCSeconds();

// Inline formatting (no helper functions)
return (
y + "-" +
(m < 10 ? "0" : "") + m + "-" +
(d < 10 ? "0" : "") + d + " " +
(h < 10 ? "0" : "") + h + ":" +
(min < 10 ? "0" : "") + min + ":" +
(s < 10 ? "0" : "") + s
);

} catch (error) {
console.error("formatTimestamp: Unexpected error →", error, "Input:", input);
return input;
}
},

formatDate: function (date, format) {
const monthNamesShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const monthNamesFull = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
Expand Down
6 changes: 3 additions & 3 deletions portality/static/js/edges/admin.background_jobs.edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ $.extend(true, doaj, {

// add the date added to doaj
if (resultobj.created_date) {
dateRow += "Job Created: " + doaj.dates.humanYearMonth(resultobj.created_date) + "<br>";
dateRow += "Job Created: " + doaj.dates.formatFullDateTime(resultobj.created_date) + "<br>";
}
if (resultobj.last_updated) {
dateRow += "Job Last Updated: " + doaj.dates.humanYearMonth(resultobj.last_updated) + "<br>";
dateRow += "Job Last Updated: " + doaj.dates.formatFullDateTime(resultobj.last_updated) + "<br>";
}

var paramsBlock = "";
Expand Down Expand Up @@ -79,7 +79,7 @@ $.extend(true, doaj, {
auditBlock += "<strong>Audit Messages:</strong><br>";
for (var i = 0; i < resultobj.audit.length; i++) {
var audit = resultobj.audit[i];
auditBlock += audit.timestamp + " -- " + edges.escapeHtml(audit.message) + "<br>";
auditBlock += doaj.dates.formatFullDateTime(audit.timestamp) + " -- " + edges.escapeHtml(audit.message) + "<br>";
}
}

Expand Down
Loading