Possible fix for #181

This commit is contained in:
Michael Teeuw 2016-04-18 19:12:24 +02:00
parent bef5b48fce
commit 8793196bb3
2 changed files with 27 additions and 12 deletions

View File

@ -48,9 +48,18 @@ Module.register("clock",{
secondsWrapper.className = "dimmed";
// Set content of wrappers.
var format = (this.config.timeFormat === 24) ? "HH:mm" : "hh:mm a";
// The moment().format('h') method has a bug on the Raspberry Pi.
// So we need to generate the timestring manually.
// See issue: https://github.com/MichMich/MagicMirror/issues/181
var timeString = moment().format('HH:mm');
if (this.config.timeFormat !== 24) {
var now = new Date();
var hours = now.getHours() % 12 || 12;
timeString = hours + moment().format(':mm a');
}
dateWrapper.innerHTML = moment().format("dddd, LL");
timeWrapper.innerHTML = moment().format(format);
timeWrapper.innerHTML = timeString;
secondsWrapper.innerHTML = moment().format("ss");
// Combine wrappers.

View File

@ -198,19 +198,25 @@ Module.register("currentweather",{
this.windSpeed = this.ms2Beaufort(this.roundValue(data.wind.speed));
this.weatherType = this.config.iconTable[data.weather[0].icon];
var now = moment();
var sunrise = moment(data.sys.sunrise * 1000);
var sunset = moment(data.sys.sunset * 1000);
var format = (this.config.timeFormat === 24) ? "HH:mm" : "hh:mm a";
var now = new Date();
var sunrise = new Date(data.sys.sunrise * 1000);
var sunset = new Date(data.sys.sunset * 1000);
if (sunrise < now && sunset > now) {
this.sunriseSunsetTime = sunset.format(format);
this.sunriseSunsetIcon = "wi-sunset";
} else {
this.sunriseSunsetTime = sunrise.format(format);
this.sunriseSunsetIcon = "wi-sunrise";
// The moment().format('h') method has a bug on the Raspberry Pi.
// So we need to generate the timestring manually.
// See issue: https://github.com/MichMich/MagicMirror/issues/181
var sunriseSunsetDateObject = (sunrise < now && sunset > now) ? sunset : sunrise;
var timeString = moment(sunriseSunsetDateObject).format('HH:mm');
if (this.config.timeFormat !== 24) {
var hours = sunriseSunsetDateObject.getHours() % 12 || 12;
timeString = hours + moment(sunriseSunsetDateObject).format(':mm a');
}
this.sunriseSunsetTime = timeString;
this.sunriseSunsetIcon = (sunrise < now && sunset > now) ? "wi-sunset" : "wi-sunrise";
this.loaded = true;
this.updateDom(this.config.animationSpeed);
},