entryCmd: Use now to parse since/until dates

This commit is contained in:
Cat /dev/Nulo 2022-09-04 17:14:29 -03:00
parent 83790d0f18
commit 36e9cb09c3

View file

@ -3,8 +3,9 @@ package z
import ( import (
"os" "os"
"fmt" "fmt"
"time"
"strings" "strings"
"github.com/jinzhu/now"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -25,7 +26,7 @@ var entryCmd = &cobra.Command{
if begin != "" || finish != "" || project != "" || notes != "" || task != "" { if begin != "" || finish != "" || project != "" || notes != "" || task != "" {
if begin != "" { if begin != "" {
entry.Begin, err = time.Parse(time.RFC3339, begin) entry.Begin, err = now.Parse(begin)
if err != nil { if err != nil {
fmt.Printf("%s %+v\n", CharError, err) fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1) os.Exit(1)
@ -33,7 +34,7 @@ var entryCmd = &cobra.Command{
} }
if finish != "" { if finish != "" {
entry.Finish, err = time.Parse(time.RFC3339, finish) entry.Finish, err = now.Parse(finish)
if err != nil { if err != nil {
fmt.Printf("%s %+v\n", CharError, err) fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1) os.Exit(1)
@ -66,8 +67,8 @@ var entryCmd = &cobra.Command{
func init() { func init() {
rootCmd.AddCommand(entryCmd) rootCmd.AddCommand(entryCmd)
entryCmd.Flags().StringVarP(&begin, "begin", "b", "", "Update date/time the activity began at\n\nUse RFC3339 format.") entryCmd.Flags().StringVarP(&begin, "begin", "b", "", "Update date/time the activity began at")
entryCmd.Flags().StringVarP(&finish, "finish", "s", "", "Update date/time the activity finished at\n\nUse RFC3339 format.") entryCmd.Flags().StringVarP(&finish, "finish", "s", "", "Update date/time the activity finished at")
entryCmd.Flags().StringVarP(&project, "project", "p", "", "Update activity project") entryCmd.Flags().StringVarP(&project, "project", "p", "", "Update activity project")
entryCmd.Flags().StringVarP(&notes, "notes", "n", "", "Update activity notes") entryCmd.Flags().StringVarP(&notes, "notes", "n", "", "Update activity notes")
entryCmd.Flags().StringVarP(&task, "task", "t", "", "Update activity task") entryCmd.Flags().StringVarP(&task, "task", "t", "", "Update activity task")