time
This commit is contained in:
parent
e5dbb66e7d
commit
6f8a9d79dc
12
cmd/time.go
12
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
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user