Working more on timer modifications

This commit is contained in:
Brian Buller 2018-05-10 10:20:51 -05:00
parent 0d2a887618
commit 95acb78140

View File

@ -10,17 +10,32 @@ import (
)
func cmdModifyTimer(args []string) int {
var err error
// If no timer id is specified, edit the most recent one
modId := "@0"
var tags, remTags, rem []string
tags, rem = pullTagsFromArgs(args)
remTags, rem = pullRemoveTagsFromArgs(rem)
var start, end time.Time
for i := range rem {
if rem[i][0] == '@' {
modId = rem[i]
}
if strings.HasPrefix(rem, "start:") {
if strings.HasPrefix(rem[i], "start:") {
stStr := strings.TrimPrefix(rem[i], "start:")
start, err = parseFuzzyTime(stStr)
if err != nil {
fmt.Println("Unable to parse start time: " + stStr)
return 1
}
}
if strings.HasPrefix(rem[i], "end:") {
endStr := strings.TrimPrefix(rem[i], "end:")
end, err = parseFuzzyTime(endStr)
if err != nil {
fmt.Println("Unable to parse end time: " + endStr)
return 1
}
}
}
timerId, err := strconv.Atoi(modId[1:])
@ -39,6 +54,20 @@ func cmdModifyTimer(args []string) int {
for i := range remTags {
tmr.RemoveTag(remTags[i])
}
if !start.IsZero() {
// TODO: Fix keying by start time
fmt.Println("Not supported")
return 1
//tmr.SetStart(start)
}
if tmr.GetEnd().IsZero() {
// At this point, timers must be stopped to modify the end date
fmt.Println("Timer has not been stopped. Cowardly refusing to modify stop time.")
return 1
}
if !end.IsZero() {
tmr.SetEnd(end)
}
if err = gdb.SaveTimeEntry(tmr); err != nil {
fmt.Println("Error saving modified timer:", err.Error())
return 1