Skip to content

Commit

Permalink
Format sunrise and sunset
Browse files Browse the repository at this point in the history
  • Loading branch information
getninjaN committed Dec 6, 2022
1 parent 602eb9b commit 7a55d3d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 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 @@ -68,6 +69,9 @@ func formatAll(result types.WeatherRes, city string) string {

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

sunriseTime := time.UnixMilli(int64(result.Sys.Sunrise) * 1000)
sunsetTime := time.UnixMilli(int64(result.Sys.Sunset) * 1000)

return "\nπŸŒ† City:\t\t" + city + "\n" +
"🌍 Country:\t\t" + result.Sys.Country + "\n" +
"⌚️ Timezone:\t\t" + strconv.Itoa(result.Timezone) + "\n" +
Expand All @@ -88,8 +92,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) + ")\n" +
"πŸŒ‡ Sunset:\t\t" + sunsetTime.Format("15:04") + " (" + sunsetTime.Format(time.Kitchen) + ")\n"
}

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

0 comments on commit 7a55d3d

Please sign in to comment.