This commit is contained in:
abs3nt 2023-02-28 00:59:26 -08:00
parent e5dbb66e7d
commit 6f8a9d79dc

View File

@ -434,7 +434,7 @@ var timeCmd = &cobra.Command{
Use: "time", Use: "time",
Short: "gets current time in given city", Short: "gets current time in given city",
Long: `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) { ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 1 { if len(args) == 1 {
return nil, cobra.ShellCompDirectiveNoFileComp return nil, cobra.ShellCompDirectiveNoFileComp
@ -443,7 +443,15 @@ var timeCmd = &cobra.Command{
}, },
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
loc, _ := time.LoadLocation(args[0]) 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 return nil
}, },
} }