Skip to content

Commit

Permalink
Merge pull request #6 from getninjaN/master
Browse files Browse the repository at this point in the history
Format sunrise and sunset
  • Loading branch information
eoin-barr authored Dec 7, 2022
2 parents 602eb9b + bac4ee9 commit 7973b36
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strconv"
"strings"
"math"
"time"

"github.com/eoin-barr/weatherme/types"
// "github.com/joho/godotenv"
Expand Down Expand Up @@ -67,6 +68,10 @@ func formatAll(result types.WeatherRes, city string) string {
tempMax := result.Main.Temp_max - 273.15

dewPoint := calculateDewPoint(temp, float64(result.Main.Humidity))

timeOffset := time.Duration(result.Timezone * int(time.Second))
sunriseTime := time.UnixMilli(int64(result.Sys.Sunrise) * 1000).Add(timeOffset).UTC()
sunsetTime := time.UnixMilli(int64(result.Sys.Sunset) * 1000).Add(timeOffset).UTC()

return "\nπŸŒ† City:\t\t" + city + "\n" +
"🌍 Country:\t\t" + result.Sys.Country + "\n" +
Expand All @@ -88,8 +93,8 @@ func formatAll(result types.WeatherRes, city string) string {
"🧭 Wind Direction:\t" + strconv.Itoa(result.Wind.Deg) + " °" + "\n" +
"🌁 Visibility:\t\t" + strconv.Itoa(result.Visibility) + "\n\n" +

"πŸŒ… Sunrise:\t\t" + strconv.Itoa(result.Sys.Sunrise) + "\n" +
"πŸŒ‡ Sunset:\t\t" + strconv.Itoa(result.Sys.Sunset) + "\n"
"πŸŒ… Sunrise:\t\t" + sunriseTime.Format("15:04") + " (" + sunriseTime.Format(time.Kitchen) + ") UTC\n" +
"πŸŒ‡ Sunset:\t\t" + sunsetTime.Format("15:04") + " (" + sunsetTime.Format(time.Kitchen) + ") UTC\n"
}

func getWeather(args []string, view string) {
Expand Down

0 comments on commit 7973b36

Please sign in to comment.