diff --git a/timer_ops_other.go b/timer_ops_other.go index 546996f..72c2107 100644 --- a/timer_ops_other.go +++ b/timer_ops_other.go @@ -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