Allow temp and wind units to be specified separately if required.

This commit is contained in:
Malcolm Oakes
2019-06-07 15:27:08 +01:00
parent 2970568eab
commit a619fc4fef
9 changed files with 48 additions and 37 deletions

View File

@@ -13,8 +13,11 @@
// As soon as we start implementing the forecast, mode properties will be added.
class WeatherObject {
constructor(units) {
constructor(units, tempUnits, windUnits) {
this.units = units;
this.tempUnits = tempUnits;
this.windUnits = windUnits;
this.date = null;
this.windSpeed = null;
this.windDirection = null;
@@ -69,7 +72,7 @@ class WeatherObject {
}
beaufortWindSpeed() {
const windInKmh = (this.units === "imperial" || this.units === "ukunits") ? this.windSpeed * 1.609344 : this.windSpeed * 60 * 60 / 1000;
const windInKmh = (this.windUnits === "imperial") ? this.windSpeed * 1.609344 : 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) {
@@ -87,8 +90,8 @@ class WeatherObject {
if (this.feelsLikeTemp) {
return this.feelsLikeTemp
}
const windInMph = (this.units === "imperial" || this.units === "ukunits") ? this.windSpeed : this.windSpeed * 2.23694;
const tempInF = this.units === "imperial" ? this.temperature : this.temperature * 9 / 5 + 32;
const windInMph = (this.windUnits === "imperial") ? this.windSpeed : this.windSpeed * 2.23694;
const tempInF = this.tempUnits === "imperial" ? this.temperature : this.temperature * 9 / 5 + 32;
let feelsLike = tempInF;
if (windInMph > 3 && tempInF < 50) {
@@ -102,6 +105,6 @@ class WeatherObject {
- 1.99 * Math.pow(10, -6) * tempInF * tempInF * this.humidity * this.humidity;
}
return this.units === "imperial" ? feelsLike : (feelsLike - 32) * 5 / 9;
return this.tempUnits === "imperial" ? feelsLike : (feelsLike - 32) * 5 / 9;
}
}