about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/App.svelte14
-rw-r--r--src/bestiary.js11
2 files changed, 10 insertions, 15 deletions
diff --git a/src/App.svelte b/src/App.svelte
index 4cc445f..502f465 100644
--- a/src/App.svelte
+++ b/src/App.svelte
@@ -28,20 +28,6 @@
   }, 10000); // 10 seconds
   $: currentEzTime = formatUtc(date);
 
-  function formatWeathers(weathers) {
-    if (weathers.length === 1) {
-      return ew.getWeatherName(weathers[0]);
-    }
-    return weathers
-      .map((w, i) => {
-        if (i + 1 === weathers.length) {
-          return `and ${ew.getWeatherName(w)}`;
-        }
-        return `${ew.getWeatherName(w)}, `;
-      })
-      .join("");
-  }
-
   function newForecasts() {
     anemosForecast = ew.forecast(ew.ANEMOS_WEATHER, "anemos");
     pagosForecast = ew.forecast(ew.PAGOS_WEATHER, "pagos");
diff --git a/src/bestiary.js b/src/bestiary.js
index b09a613..6eac997 100644
--- a/src/bestiary.js
+++ b/src/bestiary.js
@@ -46,7 +46,7 @@ function findForecastMatch(forecast, conditions) {
     isUp: forecastMatches(forecast, conditions[dn], 0),
     weathers: conditions[dn],
     futureUptime: [1, 2, 3, 4].map((i) => {
-      return forecastMatches(forecast, conditions[dn], i);
+      return futureForecastMatches(forecast, conditions, i);
     }),
   };
 }
@@ -55,3 +55,12 @@ function forecastMatches(forecast, condition, index) {
   const currWeather = forecast[index].currWeather;
   return condition.some((c) => c === currWeather);
 }
+
+function futureForecastMatches(forecast, conditions, index) {
+  const fc = forecast[index];
+  const fcTime = day((fc.date.getTime() * 1440) / 70);
+  const dn = day(fcTime).isBetween(fcTime.hour(8), fcTime.hour(18))
+    ? "day"
+    : "night";
+  return conditions[dn].some((c) => c === fc.currWeather);
+}