mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
More friendly display of alert times #32
This commit is contained in:
@@ -53,12 +53,6 @@ function updateTable() {
|
||||
next24h = alerts.filter(a => moment.unix(a["start_time"]).utc().isSameOrAfter() && moment.unix(a["start_time"]).utc().subtract(24, 'hours').isBefore());
|
||||
later = alerts.filter(a => moment.unix(a["start_time"]).utc().subtract(24, 'hours').isSameOrAfter());
|
||||
|
||||
alerts.forEach(a => {
|
||||
if (!(a in onNow) && !(a in next24h) && !(a in later)) {
|
||||
console.log(moment.unix(a["start_time"]).format('YYYY-MM-DD hh:mm') + " " + moment.unix(a["end_time"]).format('YYYY-MM-DD hh:mm'));
|
||||
}
|
||||
});
|
||||
|
||||
if (onNow.length > 0) {
|
||||
table.find('tbody').append('<tr class="table-primary"><td colspan="100" style="text-align:center;">On Now</td></tr>');
|
||||
addAlertRowsToTable(table.find('tbody'), onNow);
|
||||
@@ -88,12 +82,29 @@ function addAlertRowsToTable(tbody, alerts) {
|
||||
// Create row
|
||||
let $tr = $('<tr>');
|
||||
|
||||
// Format UTC times for display
|
||||
// Format UTC times for display. Start time is displayed as e.g. 7 Oct 12:34 unless the time is in a different
|
||||
// year to the current year, in which case the year is inserted between month and hour.
|
||||
// End time is displayed the same as above, except if the end date is the same as the start date, in which case
|
||||
// just e.g. 23:45 is used. Finally, if there is no end date set, "---" is displayed.
|
||||
var start_time = moment.unix(a["start_time"]).utc();
|
||||
var start_time_formatted = start_time.format("YYYY-MM-DD HH:mm");
|
||||
var start_time_formatted = start_time.format("D MMM HH:mm");
|
||||
if (start_time.format("YYYY") != moment().format("YYYY")) {
|
||||
start_time_formatted = start_time.format("D MMM YYYY HH:mm");
|
||||
}
|
||||
|
||||
var end_time_unix = moment.unix(a["end_time"]);
|
||||
var end_time = end_time_unix.utc();
|
||||
var end_time_formatted = (end_time_unix != null && end_time_unix > 0 && end_time != null) ? end_time.format("YYYY-MM-DD HH:mm") : "---";
|
||||
var end_time_formatted = "---";
|
||||
if (end_time_unix != null && end_time_unix > 0 && end_time != null) {
|
||||
var end_time_formatted = end_time.format("HH:mm");
|
||||
if (end_time.format("D MMM") != start_time.format("D MMM")) {
|
||||
if (end_time.format("YYYY") != moment().format("YYYY")) {
|
||||
end_time_formatted = end_time.format("D MMM YYYY HH:mm");
|
||||
} else {
|
||||
end_time_formatted = end_time.format("D MMM HH:mm");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Format DX flag
|
||||
var dx_flag = "<i class='fa-solid fa-circle-question'></i>";
|
||||
|
||||
Reference in New Issue
Block a user