Add common method for updating suntimes

This commit is contained in:
rejas
2021-08-31 21:41:27 +02:00
parent e40ddd4b69
commit 8949aa3bec
3 changed files with 16 additions and 34 deletions

View File

@@ -1,3 +1,5 @@
/* global SunCalc */
/* Magic Mirror
* Module: Weather
*
@@ -113,4 +115,16 @@ class WeatherObject {
return this.tempUnits === "imperial" ? feelsLike : ((feelsLike - 32) * 5) / 9;
}
/**
* Update the sunrise / sunset time depending on the location
*
* @param {number} lat latitude
* @param {number} lon longitude
*/
updateSunTime(lat, lon) {
let times = SunCalc.getTimes(new Date(), lat, lon);
this.sunrise = moment(times.sunrise, "X");
this.sunset = moment(times.sunset, "X");
}
}