feat: Add flag for UTC time defaults to local time

Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
Tim Hårek Andreassen 2024-10-02 20:54:36 +02:00
parent 6cb3994ae9
commit 56cd590025
No known key found for this signature in database
GPG key ID: E59C7734F0E10EB5
3 changed files with 9 additions and 1 deletions

View file

@ -5,4 +5,5 @@ const (
LAT = "lat"
JSON = "json"
INTERVAL = "interval"
UTC = "utc"
)

View file

@ -30,6 +30,8 @@ func init() {
func forecast(cmd *cobra.Command, args []string) {
isJson, err := cmd.Flags().GetBool(flags.JSON)
cobra.CheckErr(err)
isUTC, err := cmd.Flags().GetBool(flags.UTC)
cobra.CheckErr(err)
lon, _ := cmd.Flags().GetFloat64(flags.LON)
lat, _ := cmd.Flags().GetFloat64(flags.LAT)
interval, _ := cmd.Flags().GetInt(flags.INTERVAL)
@ -91,8 +93,12 @@ func forecast(cmd *cobra.Command, args []string) {
Headers("time", "temp.", "rain", "wind")
for _, item := range f {
itemTime := item.Time.Local()
if isUTC {
itemTime = item.Time
}
t.Row(
item.Time.Format(time.DateTime),
itemTime.Format(time.DateTime),
fmt.Sprintf("%.1f °C", item.Temperature),
fmt.Sprintf("%.1f mm", item.Percipitation),
fmt.Sprintf("%.1f m/s %s", item.Wind.Speed, item.Wind.DirectionToString()),

View file

@ -22,6 +22,7 @@ func Execute() {
func init() {
rootCmd.PersistentFlags().Bool(flags.JSON, false, "Result in JSON")
rootCmd.PersistentFlags().Bool(flags.UTC, false, "Result times in UTC")
rootCmd.PersistentFlags().Float64P(flags.LON, "x", 0, "Longitude coordinate")
rootCmd.PersistentFlags().Float64P(flags.LAT, "y", 0, "Latitude coordinate")
}