From f76ce1833582cbc797f02142bde498cb11b6ef39 Mon Sep 17 00:00:00 2001 From: Mikel Larreategi Date: Fri, 3 Nov 2023 18:15:28 +0100 Subject: [PATCH] improve date handling --- src/euskalmet.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/euskalmet.js b/src/euskalmet.js index a24b59c..8824d5b 100644 --- a/src/euskalmet.js +++ b/src/euskalmet.js @@ -74,10 +74,12 @@ class Euskalmet extends HTMLElement { let div = document.createElement('div'); let forecastText = item.weather.nameByLang[this.language]; div.className = 'euskalmet-forecast-day'; - const dateText = item.date.split('T')[0]; - const shortText = this.shortText ? forecastText : ''; - const imageUrl = this.customBaseUrl + let dateObject = new Date(item.date); + let dateText = `${dateObject.getFullYear()}-${dateObject.getMonth()}-${dateObject.getDate()}`; + let shortText = this.shortText ? forecastText : ''; + + let imageUrl = this.customBaseUrl ? this.customIconExtension ? `${this.customBaseUrl}/${item.weather.id}.${this.customIconExtension}` : `${this.customBaseUrl}/${item.weather.icon_name}`