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:
parent
6cb3994ae9
commit
56cd590025
3 changed files with 9 additions and 1 deletions
|
@ -5,4 +5,5 @@ const (
|
||||||
LAT = "lat"
|
LAT = "lat"
|
||||||
JSON = "json"
|
JSON = "json"
|
||||||
INTERVAL = "interval"
|
INTERVAL = "interval"
|
||||||
|
UTC = "utc"
|
||||||
)
|
)
|
||||||
|
|
|
@ -30,6 +30,8 @@ func init() {
|
||||||
func forecast(cmd *cobra.Command, args []string) {
|
func forecast(cmd *cobra.Command, args []string) {
|
||||||
isJson, err := cmd.Flags().GetBool(flags.JSON)
|
isJson, err := cmd.Flags().GetBool(flags.JSON)
|
||||||
cobra.CheckErr(err)
|
cobra.CheckErr(err)
|
||||||
|
isUTC, err := cmd.Flags().GetBool(flags.UTC)
|
||||||
|
cobra.CheckErr(err)
|
||||||
lon, _ := cmd.Flags().GetFloat64(flags.LON)
|
lon, _ := cmd.Flags().GetFloat64(flags.LON)
|
||||||
lat, _ := cmd.Flags().GetFloat64(flags.LAT)
|
lat, _ := cmd.Flags().GetFloat64(flags.LAT)
|
||||||
interval, _ := cmd.Flags().GetInt(flags.INTERVAL)
|
interval, _ := cmd.Flags().GetInt(flags.INTERVAL)
|
||||||
|
@ -91,8 +93,12 @@ func forecast(cmd *cobra.Command, args []string) {
|
||||||
Headers("time", "temp.", "rain", "wind")
|
Headers("time", "temp.", "rain", "wind")
|
||||||
|
|
||||||
for _, item := range f {
|
for _, item := range f {
|
||||||
|
itemTime := item.Time.Local()
|
||||||
|
if isUTC {
|
||||||
|
itemTime = item.Time
|
||||||
|
}
|
||||||
t.Row(
|
t.Row(
|
||||||
item.Time.Format(time.DateTime),
|
itemTime.Format(time.DateTime),
|
||||||
fmt.Sprintf("%.1f °C", item.Temperature),
|
fmt.Sprintf("%.1f °C", item.Temperature),
|
||||||
fmt.Sprintf("%.1f mm", item.Percipitation),
|
fmt.Sprintf("%.1f mm", item.Percipitation),
|
||||||
fmt.Sprintf("%.1f m/s %s", item.Wind.Speed, item.Wind.DirectionToString()),
|
fmt.Sprintf("%.1f m/s %s", item.Wind.Speed, item.Wind.DirectionToString()),
|
||||||
|
|
|
@ -22,6 +22,7 @@ func Execute() {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.PersistentFlags().Bool(flags.JSON, false, "Result in JSON")
|
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.LON, "x", 0, "Longitude coordinate")
|
||||||
rootCmd.PersistentFlags().Float64P(flags.LAT, "y", 0, "Latitude coordinate")
|
rootCmd.PersistentFlags().Float64P(flags.LAT, "y", 0, "Latitude coordinate")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue