Commit dc527ee3 authored by Leo Iannacone's avatar Leo Iannacone

move time functions to Utils

parent 81fe9292
...@@ -355,24 +355,6 @@ function Page_Distrubion(socket) { ...@@ -355,24 +355,6 @@ function Page_Distrubion(socket) {
return; return;
} }
function _get_two_digits(num) {
return ("0" + num).slice(-2);
}
function _get_time(timestamp) {
var date = new Date(timestamp * 1000);
var locale = navigator.language || 'en-US';
var options = {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
};
var result = date.toLocaleDateString(locale, options);
result += ' <b>' + _get_two_digits(date.getHours()) + ':' + _get_two_digits(date.getMinutes()) + '</b>';
return result;
}
if (socket_data.hasOwnProperty('files')) { if (socket_data.hasOwnProperty('files')) {
var s_files = socket_data.files; var s_files = socket_data.files;
for (var file in s_files) { for (var file in s_files) {
...@@ -390,15 +372,15 @@ function Page_Distrubion(socket) { ...@@ -390,15 +372,15 @@ function Page_Distrubion(socket) {
if (socket_data.uploader) if (socket_data.uploader)
info += "Uploaded by " + socket_data.uploader + ' - '; info += "Uploaded by " + socket_data.uploader + ' - ';
info += "Build started " + _get_time(socket_data.start); info += "Build started " + Utils.format_time(socket_data.start, true);
if (socket_data.end) { if (socket_data.end) {
info += ' - finished ' + _get_time(socket_data.end); info += ' - finished ' + Utils.format_time(socket_data.end, true);
info += ' - elapsed time: <b>'; info += ' - elapsed time: <b>';
var elapsed = new Date((socket_data.end - socket_data.start) * 1000); var elapsed = new Date((socket_data.end - socket_data.start) * 1000);
info += _get_two_digits(elapsed.getUTCHours()) + ':'; info += Utils.num_two_digits(elapsed.getUTCHours()) + ':';
info += _get_two_digits(elapsed.getUTCMinutes()) + ':'; info += Utils.num_two_digits(elapsed.getUTCMinutes()) + ':';
info += _get_two_digits(elapsed.getUTCSeconds()); info += Utils.num_two_digits(elapsed.getUTCSeconds());
} }
$("#package_info").html(info); $("#package_info").html(info);
......
...@@ -7,14 +7,15 @@ ...@@ -7,14 +7,15 @@
/* global dom_history: false */ /* global dom_history: false */
function Page_History() { function Page_History() {
// init table
for (var i = 0; i < dom_history.length; i++) { for (var i = 0; i < dom_history.length; i++) {
var p = dom_history[i]; var p = dom_history[i];
var row = '<tr>'; var row = '<tr>';
row += '<td>' + p.distribution + '</td>'; row += '<td>' + p.distribution + '</td>';
row += '<td>' + p.package + '</td>'; row += '<td>' + p.package + '</td>';
row += '<td>' + p.uploader + '</td>'; row += '<td>' + p.uploader + '</td>';
row += '<td>' + p.start + '</td>'; row += '<td>' + Utils.format_time(p.start) + '</td>';
row += '<td>' + p.end + '</td>'; row += '<td>' + Utils.format_time(p.end) + '</td>';
row += '<td>' + p.status + '</td>'; row += '<td>' + p.status + '</td>';
row += '</tr>'; row += '</tr>';
$('.table tbody').append(row); $('.table tbody').append(row);
......
...@@ -105,5 +105,27 @@ var Utils = { ...@@ -105,5 +105,27 @@ var Utils = {
"/": "&#x2F;" "/": "&#x2F;"
}[s]; }[s];
}); });
},
// returns a two digits num
num_two_digits: function (num) {
return ("0" + num).slice(-2);
},
// format time from a timestamp
format_time: function (timestamp, time_in_bold) {
var date = new Date(timestamp * 1000);
var locale = navigator.language || 'en-US';
var options = {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
};
var result_date = date.toLocaleDateString(locale, options);
var result_time = Utils.num_two_digits(date.getHours()) + ':' + Utils.num_two_digits(date.getMinutes());
if (time_in_bold) result_time = '<b>' + result_time + '</b>';
return result_date + ' ' + result_time;
} }
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment