From 6f8a9d79dc80d9e50dd0239ad22858ffe55d4508 Mon Sep 17 00:00:00 2001 From: abs3nt Date: Tue, 28 Feb 2023 00:59:26 -0800 Subject: [PATCH] time --- cmd/time.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 }, }