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"
|
||||
JSON = "json"
|
||||
INTERVAL = "interval"
|
||||
UTC = "utc"
|
||||
)
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue