Working on it

This commit is contained in:
2017-08-02 14:14:53 -05:00
parent 0127427d18
commit 3d420d20ba
6 changed files with 75 additions and 27 deletions

View File

@@ -7,22 +7,25 @@ import (
"git.bullercodeworks.com/brian/gime"
)
// TimerToString takes a TimeEntry and gives a nicely formatted string
func TimerToString(t *gime.TimeEntry) string {
var ret string
var end string
if t.StartsToday() {
ret = t.GetStart().Format("15:04 - ")
end = "**:**"
} else {
ret = t.GetStart().Format("2006/01/02 15:04:05 - ")
end = "**:**:**"
}
if !t.GetEnd().IsZero() {
if t.EndsToday() {
ret += t.GetEnd().Format("15:04")
end = t.GetEnd().Format("15:04")
} else {
ret += t.GetEnd().Format("2006/01/02 15:04:05")
end = t.GetEnd().Format("2006/01/02 15:04:05")
}
} else {
ret += "**:**:**"
}
ret += end
tags := t.GetTags()
if tags.Length() > 0 {
ret += " [ "

View File

@@ -47,6 +47,8 @@ func main() {
ret = cmdPrintStatus()
case "start":
ret = cmdStartTimer(parms[1:])
case "switch":
ret = cmdSwitchTimer(parms[1:])
case "end", "stop":
ret = cmdStopTimer(parms[1:])
case "list", "ls":
@@ -118,16 +120,14 @@ func loadActiveTimeEntries() {
}
func cmdPrintList(args []string) int {
/*
var err error
loadActiveTimeEntries()
// By default, list all entries for today
currTime := time.Now()
dur := currTime.Hour()*time.Hour + currTime.Minute()*time.Minute
if len(args) < 1 {
var err error
loadActiveTimeEntries()
// By default, list all entries for today
currTime := time.Now()
dur := currTime.Hour()*time.Hour + currTime.Minute()*time.Minute
if len(args) < 1 {
}
*/
}
return 0
}
@@ -216,6 +216,10 @@ func initialize() {
" If the first sub-argument given looks like a time,",
" the timer will be stopped then (past or future).",
}
validOperations["switch"] = []string{
"switch [tags ...] - Stop all currently running timers and start a new",
" one with the given tags",
}
// Load the Config
cfg, err = userConfig.NewConfig(AppName)

View File

@@ -10,9 +10,23 @@ import (
// switchTimer performs a stop on any currently running timers
// and starts a new timer with the given arguments
func switchTimer(args []string) int {
func cmdSwitchTimer(args []string) int {
loadActiveTimeEntries()
return 0
tm := time.Now()
if activeTimeEntries.Length() > 0 {
fmt.Println("Stopped Timers:")
}
for i := 0; i < activeTimeEntries.Length(); i++ {
tmr := activeTimeEntries.Get(i)
tmr.SetEnd(tm)
if err := gdb.UpdateTimeEntry(tmr); err != nil {
fmt.Println(err.Error())
return 1
}
fmt.Println(" " + TimerToString(tmr))
}
fmt.Println("Started Timer:")
return cmdStartTimer(args)
}
// cmdStartTimer takes a list of arguments and returns the return code
@@ -40,7 +54,6 @@ func cmdStartTimer(args []string) int {
if tagStart < len(args) {
timerArgs = args[tagStart:]
}
fmt.Println(tm)
tc := new(gime.TagCollection)
for i := range timerArgs {
tc.Push(timerArgs[i])
@@ -53,6 +66,7 @@ func cmdStartTimer(args []string) int {
fmt.Println(err)
return 1
}
fmt.Println(" " + TimerToString(entry))
return 0
}