Skip to content

Commit 79e7aa1

Browse files
committed
timezone fix
1 parent af77ecf commit 79e7aa1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@
262262
"lang": {
263263
"type": "string"
264264
},
265+
"forecast": {
266+
"type": "boolean",
267+
"default": false,
268+
"description": "Whether to include 3 day forecast data"
269+
},
265270
"default": {
266271
"type": "boolean"
267272
}

internal/templates/partials/weather.templ

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ templ weatherIcon(ID int) {
7979
}
8080
}
8181

82-
func forecastItemData(datetime int) (bool, string) {
83-
t := time.Unix(int64(datetime), 0)
84-
now := time.Now().In(t.Location())
82+
func forecastItemData(datetime, tzOffset int) (bool, string) {
83+
loc := time.FixedZone("owm", tzOffset)
84+
t := time.Unix(int64(datetime), 0).In(loc)
85+
now := time.Now().In(loc)
8586
isToday := t.Year() == now.Year() &&
8687
t.Month() == now.Month() &&
8788
t.Day() == now.Day()
@@ -118,7 +119,11 @@ templ WeatherLocation(weatherData weather.Location) {
118119
<div class="weather--forecast">
119120
for _, f := range weatherData.Forecast.List {
120121
{{
121-
isToday, forecastDay := forecastItemData(f.DT)
122+
if len(f.Data) == 0 {
123+
continue
124+
}
125+
126+
isToday, forecastDay := forecastItemData(f.DT, weatherData.Timezone)
122127
if isToday {
123128
continue
124129
}

0 commit comments

Comments
 (0)