Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 834a857227 | |||
| 729084ae74 | |||
| b30d663eb1 |
4
.tmuxrc
Normal file
4
.tmuxrc
Normal file
@@ -0,0 +1,4 @@
|
||||
rename-window dev
|
||||
neww -n build
|
||||
neww -n run
|
||||
select-window -t 0:0
|
||||
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 Brian Buller <brian@bullercodeworks.com>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
@@ -74,6 +73,7 @@ func opListTimers(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
filter := util.BuildFilterFromArgs(args)
|
||||
list = list.Filter(filter)
|
||||
list.Sort(timertxt.SortFinishDateAsc)
|
||||
|
||||
dayTotals := make(map[string]time.Duration)
|
||||
for _, v := range list.GetTimerSlice() {
|
||||
|
||||
43
cmd/time.go
43
cmd/time.go
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 Brian Buller <brian@bullercodeworks.com>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
@@ -10,37 +9,71 @@ import (
|
||||
|
||||
"git.bullercodeworks.com/brian/gime/cli"
|
||||
"git.bullercodeworks.com/brian/gime/util"
|
||||
"git.bullercodeworks.com/brian/go-timertxt"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// timeCmd represents the time command
|
||||
var timeCmd = &cobra.Command{
|
||||
Use: "time",
|
||||
Short: "A brief description of your command",
|
||||
Short: "Output the total time for the given contexts/projects",
|
||||
RunE: opShowTimers,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(timeCmd)
|
||||
|
||||
// Local Flags
|
||||
timeCmd.Flags().BoolP("all", "a", false, "Include done.txt timers")
|
||||
timeCmd.Flags().BoolP("done", "d", false, "Only done.txt timers")
|
||||
}
|
||||
|
||||
func opShowTimers(cmd *cobra.Command, args []string) error {
|
||||
var err error
|
||||
var includeArchive bool
|
||||
var onlyArchive bool
|
||||
if onlyArchive, err = cmd.Flags().GetBool("done"); err != nil {
|
||||
return err
|
||||
} else if includeArchive, err = cmd.Flags().GetBool("all"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p := cli.Program{}
|
||||
err = p.Initialize()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !onlyArchive {
|
||||
if err := p.LoadTimerList(); err != nil {
|
||||
return err
|
||||
}
|
||||
list := p.GetFilteredTimerList(args)
|
||||
}
|
||||
if includeArchive || onlyArchive {
|
||||
if err := p.LoadDoneList(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
list := timertxt.NewTimerList()
|
||||
if !onlyArchive {
|
||||
list = p.TimerList
|
||||
if includeArchive {
|
||||
for _, tmr := range p.DoneList.GetTimerSlice() {
|
||||
list.AddTimer(tmr)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
list = p.DoneList
|
||||
}
|
||||
filter := util.BuildFilterFromArgs(args)
|
||||
list = list.Filter(filter)
|
||||
list.Sort(timertxt.SortFinishDateAsc)
|
||||
|
||||
var isActive bool
|
||||
var total time.Duration
|
||||
for _, v := range list.GetTimerSlice() {
|
||||
dur := v.FinishDate.Sub(v.StartDate)
|
||||
dur := util.Round(v.FinishDate.Sub(v.StartDate))
|
||||
if v.FinishDate.IsZero() {
|
||||
dur = time.Now().Sub(v.StartDate)
|
||||
dur = util.Round(time.Now().Sub(v.StartDate))
|
||||
isActive = true
|
||||
}
|
||||
total += dur
|
||||
|
||||
2
go.mod
2
go.mod
@@ -9,7 +9,7 @@ replace git.bullercodeworks.com/brian/wandle => /home/brbuller/Development/go/sr
|
||||
replace git.bullercodeworks.com/brian/widdles => /home/brbuller/Development/go/src/git.bullercodeworks.com/brian/widdles
|
||||
|
||||
require (
|
||||
git.bullercodeworks.com/brian/go-timertxt v0.0.0-20210302170637-d35b67037e23
|
||||
git.bullercodeworks.com/brian/go-timertxt v1.5.0
|
||||
git.bullercodeworks.com/brian/wandle v1.0.3
|
||||
git.bullercodeworks.com/brian/widdles v0.0.0-00010101000000-000000000000
|
||||
github.com/br0xen/termbox-util v0.0.0-20200220160819-dc6d6950ba00
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
*/
|
||||
type PromptForTagWiddle struct {
|
||||
active bool
|
||||
visible bool
|
||||
x, y, w, h int
|
||||
|
||||
origKey, origVal string
|
||||
@@ -36,8 +37,8 @@ func NewPromptForTagWiddle(x, y, w, h int, key, val string) *PromptForTagWiddle
|
||||
origKey: key, origVal: val,
|
||||
keyInput: keyInp,
|
||||
valInput: widdles.NewToggleField("Value", val, 0, 0, 0, 0),
|
||||
cancelButton: widdles.NewButton("Cancel", 0, 0, 0, 0),
|
||||
doneButton: widdles.NewButton("Done", 0, 0, 0, 0),
|
||||
cancelButton: widdles.NewButton("Cancel"),
|
||||
doneButton: widdles.NewButton("Done"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +87,8 @@ func (w *PromptForTagWiddle) View(style wandle.Style) {
|
||||
wandle.Print(w.x+1, w.y+w.h-2, style, w.msg)
|
||||
}
|
||||
|
||||
func (w *PromptForTagWiddle) SetVisible(v bool) { w.visible = v }
|
||||
func (w *PromptForTagWiddle) IsVisible() bool { return w.visible }
|
||||
func (w *PromptForTagWiddle) IsActive() bool { return w.active }
|
||||
func (w *PromptForTagWiddle) SetActive(b bool) { w.active = b }
|
||||
func (w *PromptForTagWiddle) Focusable() bool { return true }
|
||||
|
||||
@@ -102,9 +102,11 @@ func DurationToDecimal(dur time.Duration) float64 {
|
||||
mins := dur.Minutes() - (dur.Hours() * 60)
|
||||
return dur.Hours() + (mins / 60)
|
||||
}
|
||||
|
||||
func AddDurations(dur1, dur2 time.Duration) time.Duration {
|
||||
return time.Duration(int64(dur1) + int64(dur2))
|
||||
}
|
||||
|
||||
func SubDurations(dur1, dur2 time.Duration) time.Duration {
|
||||
return time.Duration(int64(dur1) - int64(dur2))
|
||||
}
|
||||
@@ -167,6 +169,23 @@ func ParseFuzzyTime(t string) (time.Time, error) {
|
||||
return ret, nil
|
||||
}
|
||||
}
|
||||
// Check for some custom string values
|
||||
now := time.Now()
|
||||
y, m, d := now.Date()
|
||||
switch t {
|
||||
case "today", "today-start", "day", "day-start":
|
||||
return time.Date(y, m, d, 0, 0, 0, 0, now.Location()), nil
|
||||
case "today-end", "day-end":
|
||||
return time.Date(y, m, d, 23, 59, 59, 0, now.Location()).Add(-time.Duration(time.Nanosecond)), nil
|
||||
case "month", "month-start":
|
||||
return time.Date(y, m, 1, 0, 0, 0, 0, now.Location()), nil
|
||||
case "month-end":
|
||||
return time.Date(y, m+1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Duration(time.Nanosecond)), nil
|
||||
case "year", "year-start":
|
||||
return time.Date(y, 1, 1, 0, 0, 0, 0, now.Location()), nil
|
||||
case "year-end":
|
||||
return time.Date(y+1, 1, 1, 0, 0, 0, 0, now.Location()).Add(-time.Duration(time.Nanosecond)), nil
|
||||
}
|
||||
return time.Time{}, errors.New("Unable to parse time: " + t)
|
||||
}
|
||||
|
||||
@@ -359,24 +378,40 @@ func BuildFilterFromArgs(args []string) func(*timertxt.Timer) bool {
|
||||
end := time.Now()
|
||||
var contextFilters []string
|
||||
var projectFilters []string
|
||||
var tagFilters []string
|
||||
var allFilters []func(timertxt.Timer) bool
|
||||
if len(args) > 0 {
|
||||
contextFilters, args = GetContextsFromSlice(args)
|
||||
projectFilters, args = GetProjectsFromSlice(args)
|
||||
tagFilters, args = GetAdditionalTagsFromSlice(args)
|
||||
}
|
||||
if len(args) > 0 {
|
||||
// Bounded by time. Parse the start time.
|
||||
if args[0] == "today" || args[0] == "day" || args[0] == "month" || args[0] == "year" {
|
||||
args[0] = fmt.Sprintf("%s-start", args[0])
|
||||
if len(args) == 1 {
|
||||
args = append(args, fmt.Sprintf("%s-end", args[0]))
|
||||
}
|
||||
}
|
||||
var err error
|
||||
if start, err = ParseFuzzyTime(args[0]); err != nil {
|
||||
// Error parsing start date
|
||||
y, m, d := time.Now().Date()
|
||||
start = time.Date(y, m, d, 0, 0, 0, 0, time.Now().Location())
|
||||
} else {
|
||||
// Not sure what this arg is, discard it.
|
||||
args = args[1:]
|
||||
}
|
||||
if len(args) > 0 {
|
||||
if args[0] == "today" || args[0] == "day" || args[0] == "month" || args[0] == "year" {
|
||||
args[0] = fmt.Sprintf("%s-end", args[0])
|
||||
}
|
||||
// Parse the end time
|
||||
if end, err = ParseFuzzyTime(args[0]); err != nil {
|
||||
y, m, d := time.Now().Date()
|
||||
end = time.Date(y, m, d, 23, 59, 59, 0, time.Now().Location())
|
||||
} else {
|
||||
// Not sure what this arg is, discard it.
|
||||
args = args[1:]
|
||||
}
|
||||
}
|
||||
@@ -412,6 +447,20 @@ func BuildFilterFromArgs(args []string) func(*timertxt.Timer) bool {
|
||||
return true
|
||||
})
|
||||
}
|
||||
if len(tagFilters) > 0 {
|
||||
allFilters = append(allFilters, func(t timertxt.Timer) bool {
|
||||
for _, v := range tagFilters {
|
||||
pts := strings.Split(v, ":")
|
||||
if len(pts) < 2 || !t.HasTag(pts[0]) || t.GetTag(pts[0]) != pts[1] {
|
||||
return false
|
||||
}
|
||||
//if len(pts) == 2 && t.HasTag(pts[0]) && t.GetTag(pts[0]) == pts[1] {
|
||||
// return true
|
||||
//}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
doFilters := func(t *timertxt.Timer) bool {
|
||||
for _, v := range allFilters {
|
||||
if !v(*t) {
|
||||
@@ -441,6 +490,7 @@ func StringSliceContains(sl []string, val string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func AppendStringIfDistinct(sl []string, val string) []string {
|
||||
if !StringSliceContains(sl, val) {
|
||||
return append(sl, val)
|
||||
|
||||
Reference in New Issue
Block a user