diff --git a/cmd/time.go b/cmd/time.go index 52834bf..190067c 100644 --- a/cmd/time.go +++ b/cmd/time.go @@ -434,7 +434,7 @@ var timeCmd = &cobra.Command{ Use: "time", Short: "gets current time in given city", Long: `gets current time in given city`, - Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), + Args: cobra.MatchAll(cobra.RangeArgs(1, 2), cobra.OnlyValidArgs), ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) == 1 { return nil, cobra.ShellCompDirectiveNoFileComp @@ -443,7 +443,15 @@ var timeCmd = &cobra.Command{ }, RunE: func(cmd *cobra.Command, args []string) error { loc, _ := time.LoadLocation(args[0]) - fmt.Println(time.Now().In(loc)) + if len(args) == 2 { + t, err := time.Parse("03:04PM", args[1]) + if err != nil { + return err + } + fmt.Println(t.In(loc).Format("03:04PM")) + return nil + } + fmt.Println(time.Now().In(loc).Format("03:04PM")) return nil }, }