Add new parameter "useKmh" to weather module

Add new parameter "useKmh" to weather module for displaying wind speed as km/h instead of m/s when windUnits is set to metric.
This commit is contained in:
Aurélien Veillard
2020-11-08 14:01:02 +01:00
parent 0d6f736c2c
commit 1460f002ab
8 changed files with 40 additions and 29 deletions

View File

@@ -10,10 +10,11 @@
* As soon as we start implementing the forecast, mode properties will be added.
*/
class WeatherObject {
constructor(units, tempUnits, windUnits) {
constructor(units, tempUnits, windUnits, useKmh) {
this.units = units;
this.tempUnits = tempUnits;
this.windUnits = windUnits;
this.useKmh = useKmh;
this.date = null;
this.windSpeed = null;
this.windDirection = null;
@@ -67,7 +68,7 @@ class WeatherObject {
}
beaufortWindSpeed() {
const windInKmh = this.windUnits === "imperial" ? this.windSpeed * 1.609344 : (this.windSpeed * 60 * 60) / 1000;
const windInKmh = this.windUnits === "imperial" ? this.windSpeed * 1.609344 : (this.useKmh ? this.windSpeed : (this.windSpeed * 60 * 60) / 1000);
const speeds = [1, 5, 11, 19, 28, 38, 49, 61, 74, 88, 102, 117, 1000];
for (const [index, speed] of speeds.entries()) {
if (speed > windInKmh) {