1
0
Fork 0
mirror of https://github.com/Luzifer/worktime.git synced 2024-12-22 14:01:17 +00:00

Support "today" and "now" in date input

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2017-09-22 12:43:23 +02:00
parent 054c7846a8
commit b6b5486cf0
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
6 changed files with 16 additions and 7 deletions

View file

@ -18,7 +18,7 @@ var addCmd = &cobra.Command{
return fmt.Errorf("Please supply required arguments")
}
day, err := time.Parse("2006-01-02", args[0])
day, err := parseTime("2006-01-02", args[0])
if err != nil {
return fmt.Errorf("'day' parameter seems to have a wrong format: %s", err)
}

11
cmd/helpers.go Normal file
View file

@ -0,0 +1,11 @@
package cmd
import "time"
func parseTime(format, input string) (time.Time, error) {
if input == "today" || input == "now" {
input = time.Now().Format(format)
}
return time.Parse(format, input)
}

View file

@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"strings"
"time"
"github.com/Luzifer/worktime/schema"
"github.com/spf13/cobra"
@ -19,7 +18,7 @@ var patchCmd = &cobra.Command{
return fmt.Errorf("Please supply required arguments")
}
day, err := time.Parse("2006-01-02", args[0])
day, err := parseTime("2006-01-02", args[0])
if err != nil {
return fmt.Errorf("'day' parameter seems to have a wrong format: %s", err)
}

View file

@ -28,7 +28,7 @@ var removeCmd = &cobra.Command{
return fmt.Errorf("Please supply required arguments")
}
day, err := time.Parse("2006-01-02", inDay)
day, err := parseTime("2006-01-02", inDay)
if err != nil {
return fmt.Errorf("'day' parameter seems to have a wrong format: %s", err)
}

View file

@ -21,7 +21,7 @@ var showCmd = &cobra.Command{
args = []string{time.Now().Format("2006-01-02")}
}
day, err := time.Parse("2006-01-02", args[0])
day, err := parseTime("2006-01-02", args[0])
if err != nil {
return fmt.Errorf("'day' parameter seems to have a wrong format: %s", err)
}

View file

@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"strings"
"time"
"github.com/Luzifer/worktime/schema"
"github.com/spf13/cobra"
@ -25,7 +24,7 @@ var tagCmd = &cobra.Command{
return fmt.Errorf("Please supply required arguments")
}
day, err := time.Parse("2006-01-02", args[0])
day, err := parseTime("2006-01-02", args[0])
if err != nil {
return fmt.Errorf("'day' parameter seems to have a wrong format: %s", err)
}