From 9a05dc1034e6020dc6d6cd33324b1c0ecca9ac89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Sat, 14 Jan 2023 21:55:41 -0500 Subject: [PATCH] Added dateparse parsing, updated deps --- go.mod | 9 ++-- go.sum | 13 ++++++ z/entryCmd.go | 127 +++++++++++++++++++++++++------------------------- 3 files changed, 82 insertions(+), 67 deletions(-) diff --git a/go.mod b/go.mod index bd5aab0..1725876 100644 --- a/go.mod +++ b/go.mod @@ -13,15 +13,16 @@ require ( ) require ( - github.com/inconshreveable/mousetrap v1.0.1 // indirect + github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/tidwall/btree v1.5.2 // indirect - github.com/tidwall/gjson v1.14.3 // indirect + github.com/tidwall/btree v1.6.0 // indirect + github.com/tidwall/gjson v1.14.4 // indirect github.com/tidwall/grect v0.1.4 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect github.com/tidwall/rtred v0.1.2 // indirect github.com/tidwall/tinyqueue v0.1.1 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect - golang.org/x/sys v0.2.0 // indirect + golang.org/x/sys v0.4.0 // indirect ) diff --git a/go.sum b/go.sum index b922080..83c0619 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA= +github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw= github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 h1:ox2F0PSMlrAAiAdknSRMDrAr8mfxPCfSZolH+/qQnyQ= github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08/go.mod h1:pCxVEbcm3AMg7ejXyorUXi6HQCzOIBf7zEDVPtw0/U4= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= @@ -17,11 +19,16 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q= @@ -51,6 +58,8 @@ github.com/tidwall/btree v1.4.2 h1:PpkaieETJMUxYNADsjgtNRcERX7mGc/GP2zp/r5FM3g= github.com/tidwall/btree v1.4.2/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE= github.com/tidwall/btree v1.5.2 h1:5eA83Gfki799V3d3bJo9sWk+yL2LRoTEah3O/SA6/8w= github.com/tidwall/btree v1.5.2/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= +github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg= +github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= github.com/tidwall/buntdb v1.2.9 h1:XVz684P7X6HCTrdr385yDZWB1zt/n20ZNG3M1iGyFm4= github.com/tidwall/buntdb v1.2.9/go.mod h1:IwyGSvvDg6hnKSIhtdZ0AqhCZGH8ukdtCAzaP8fI1X4= github.com/tidwall/buntdb v1.2.10 h1:U/ebfkmYPBnyiNZIirUiWFcxA/mgzjbKlyPynFsPtyM= @@ -62,6 +71,8 @@ github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo= github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw= github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM= +github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/grect v0.1.4 h1:dA3oIgNgWdSspFzn1kS4S/RDpZFLrIxAZOdJKjYapOg= github.com/tidwall/grect v0.1.4/go.mod h1:9FBsaYRaR0Tcy4UwefBX/UDcDcDy9V5jUcxHzv2jd5Q= github.com/tidwall/lotsa v1.0.2 h1:dNVBH5MErdaQ/xd9s769R31/n2dXavsQ0Yf4TMEHHw8= @@ -91,6 +102,8 @@ golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 h1:v6hYoSR9T5oet+pMXwUWkbiVq golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/z/entryCmd.go b/z/entryCmd.go index 7864bec..cf4a63b 100644 --- a/z/entryCmd.go +++ b/z/entryCmd.go @@ -1,82 +1,83 @@ package z import ( - "os" - "fmt" - "time" - "strings" - "github.com/spf13/cobra" + "fmt" + "os" + "strings" + + "github.com/araddon/dateparse" + "github.com/spf13/cobra" ) var entryCmd = &cobra.Command{ - Use: "entry ([flags]) [id]", - Short: "Display or update activity", - Long: "Display or update tracked activity.", - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - user := GetCurrentUser() - id := args[0] + Use: "entry ([flags]) [id]", + Short: "Display or update activity", + Long: "Display or update tracked activity.", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + user := GetCurrentUser() + id := args[0] - entry, err := database.GetEntry(user, id) - if err != nil { - fmt.Printf("%s %+v\n", CharError, err) - os.Exit(1) - } + entry, err := database.GetEntry(user, id) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } - if begin != "" || finish != "" || project != "" || notes != "" || task != "" { - if begin != "" { - entry.Begin, err = time.Parse(time.RFC3339, begin) - if err != nil { - fmt.Printf("%s %+v\n", CharError, err) - os.Exit(1) - } - } + if begin != "" || finish != "" || project != "" || notes != "" || task != "" { + if begin != "" { + entry.Begin, err = dateparse.ParseAny(begin) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + } - if finish != "" { - entry.Finish, err = time.Parse(time.RFC3339, finish) - if err != nil { - fmt.Printf("%s %+v\n", CharError, err) - os.Exit(1) - } - } + if finish != "" { + entry.Finish, err = dateparse.ParseAny(finish) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + } - if project != "" { - entry.Project = project - } + if project != "" { + entry.Project = project + } - if task != "" { - entry.Task = task - } + if task != "" { + entry.Task = task + } - if notes != "" { - entry.Notes = strings.Replace(notes, "\\n", "\n", -1) - } + if notes != "" { + entry.Notes = strings.Replace(notes, "\\n", "\n", -1) + } - _, err = database.UpdateEntry(user, entry) - if err != nil { - fmt.Printf("%s %+v\n", CharError, err) - os.Exit(1) - } - } + _, err = database.UpdateEntry(user, entry) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + } - fmt.Printf("%s %s\n", CharInfo, entry.GetOutput(true)) - return - }, + fmt.Printf("%s %s\n", CharInfo, entry.GetOutput(true)) + return + }, } func init() { - rootCmd.AddCommand(entryCmd) - entryCmd.Flags().StringVarP(&begin, "begin", "b", "", "Update date/time the activity began at\n\nUse RFC3339 format.") - entryCmd.Flags().StringVarP(&finish, "finish", "s", "", "Update date/time the activity finished at\n\nUse RFC3339 format.") - entryCmd.Flags().StringVarP(&project, "project", "p", "", "Update activity project") - entryCmd.Flags().StringVarP(¬es, "notes", "n", "", "Update activity notes") - entryCmd.Flags().StringVarP(&task, "task", "t", "", "Update activity task") - entryCmd.Flags().BoolVar(&fractional, "decimal", false, "Show fractional hours in decimal format instead of minutes") + rootCmd.AddCommand(entryCmd) + 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") + entryCmd.Flags().StringVarP(&project, "project", "p", "", "Update activity project") + entryCmd.Flags().StringVarP(¬es, "notes", "n", "", "Update activity notes") + entryCmd.Flags().StringVarP(&task, "task", "t", "", "Update activity task") + entryCmd.Flags().BoolVar(&fractional, "decimal", false, "Show fractional hours in decimal format instead of minutes") - var err error - database, err = InitDatabase() - if err != nil { - fmt.Printf("%s %+v\n", CharError, err) - os.Exit(1) - } + var err error + database, err = InitDatabase() + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } }