AM/PM
Opened this issue · 1 comments
BadArms37 commented
Great dashboard! I love it!
For my own local viewing, I modified the script.js to show the current time in AM/PM like this:
function showDateTime() {
var now = new Date();
$("#currentDate").text(week[now.getDay()] + ', ' + now.getDate() + ' ' + month[now.getMonth()]);
//$("#currentTime").text(now.getHours() + (now.getMinutes() < 10 ? ":0" : ":") + now.getMinutes());
var hours = now.getHours();
var minutes = now.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
$("#currentTime").text(strTime);
}
Of course the hourly forecast could also use a similar modification, but I haven't progressed that far...
BadArms37 commented
Modified this function to show am/pm on the hourly forecasts:
function showHourlyForecast(hourlyForecasts) {
var hours = [];
var icons = [];
var temps = [];
var winds = [];
var humidities = [];
var accumulations = [];
var precipitations = [];
var i = 0;
var now = new Date();
now = now.setHours(now.getHours(), 0, 0, 0);
$.each(hourlyForecasts, function (index, hourly) {
var dateTime = new Date(0);
dateTime.setUTCSeconds(hourly.time);
var dayDate = dateTime.setHours(dateTime.getHours(), 0, 0, 0);
if (dayDate >= now || debugging) {
//hours.push("<th>" + dateTime.getHours() + "h</th>");
var hour = dateTime.getHours();
var ampm = hour >= 12 ? 'p' : 'a';
hour = hour % 12;
hour = hour ? hour : 12; // the hour '0' should be '12'
var strTime = hour + ampm;
hours.push("<th>" + strTime + "</th>");
if (showHourlyIcon){icons.push('<td><i class="' + getIconClass(hourly.icon, true) + '"></i></td>');}
temps.push('<td>' + Math.round(hourly.temperature) + '°</td>');
winds.push('<td>' + getWind(hourly.windSpeed, hourly.windBearing, showHourlyWindBearing) + '</td>');
humidities.push('<td><span style="font-size:12px">rh</span> ' + getProbability(hourly.humidity) + '<span>%</span></td>');
accumulations.push('<td>' + getAccumulationStr(hourly, 1) + '</td>');
precipitations.push('<td>' + getProbability(hourly.precipProbability) + '<span>%</span></td>');
}
i++;
if (i >= hourlyNbOfHours) {
return false;
}
});
$("#hourlyHours").html(hours.join(""));
$("#hourlyIcons").html(icons.join(""));
$("#hourlyTemp").html(temps.join(""));
$("#hourlyWind").html(winds.join(""));
$("#hourlyHumidity").html(humidities.join(""));
$("#hourlyAcc").html(accumulations.join(""));
$("#hourlyPrec").html(precipitations.join(""));
}