Commit: 5ab48819bbdbb028eb2c3bc7d56efa21c422c6e9 Parent: 94e09364f17c28708518a901fc46e7739181c36a Author: Vi Grey Date: 2024-06-19 22:18 UTC Summary: Fix 5 day forecast start day CHANGELOG.txt | 13 +++++++------ src/weather-nws.go | 13 +++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 6216c54..7057a1d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,36 +3,37 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) + +## [0.0.3] - 2024-06-19 + +### Fixed +- 5 day forecast start date + + ## [0.0.2] - 2024-06-19 ### Added - Weather forecast if latitude/longitude included ### Removed - - topbar support ### Changed - - Mimimum Go version to 1.21 - CHANGELOG.md to CHANGELOG.txt - ## [0.0.1] - 2023-08-16 ### Fixed - - Colon after Apparent Temperature printout ### Changed - - Use metar weather rather than weather struct for temp C ## [0.0.0] - 2023-08-04 ### Added - - Initial release diff --git a/src/weather-nws.go b/src/weather-nws.go index 89b721c..bb98538 100644 --- a/src/weather-nws.go +++ b/src/weather-nws.go @@ -193,6 +193,7 @@ func main() { } var latestShown bool var hourlyStarted bool + var lastEndTime time.Time for x := 0; x < len(hf.Properties.Periods); x++ { h := hf.Properties.Periods[x] if h.StartTime.Before(time.Now()) && time.Now().Before(h.EndTime) { @@ -201,6 +202,7 @@ func main() { } if h.StartTime.Before(time.Now().Add(24*time.Hour)) && time.Now().Before(h.EndTime) { + lastEndTime = h.EndTime wS := 0 windSpeedSplit := strings.Split(h.WindSpeed, " ") if len(windSpeedSplit) > 0 { @@ -221,13 +223,20 @@ func main() { hourlyStarted = true } } + timeOffset := lastEndTime.Hour()*-3600 + lastEndTime.Minute()*60 + + lastEndTime.Second() + + lastEndTime = lastEndTime.Add(time.Duration(timeOffset) * time.Second) fmt.Println("\n## Next 5 Days:") var forecastStarted bool var day int for x := 0; x < len(f.Properties.Periods); x++ { fr := f.Properties.Periods[x] - if time.Now().Add(24 * time.Hour).Before(fr.StartTime) { - if !forecastStarted && fr.StartTime.Hour() != 6 { + if lastEndTime.Before(fr.StartTime) { + if fr.StartTime.Hour() == 6 { + forecastStarted = true + } + if !forecastStarted { continue } forecastStarted = true