package main import ( "errors" "strconv" "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() { end = t.GetEnd().Format("15:04") } else { end = t.GetEnd().Format("2006/01/02 15:04:05") } } ret += end tags := t.GetTags() if tags.Length() > 0 { ret += " [ " for i := 0; i < tags.Length(); i++ { ret += tags.Get(i) + " " } ret += "]" } return ret } // findTimerById takes a timer id and returns the TimeEntry and the type string // of the entry corresponding to that id // It searches TypeCurrent -> TypeRecent -> TypeArchive func findTimerById(tmrId int) (*gime.TimeEntry, string, error) { // Find the timer for this tmrId var prevNum, numLoaded int for i := range gdb.AllTypes { timeCollection := gdb.LoadTimeEntryCollection(gdb.AllTypes[i]) numLoaded += timeCollection.Length() if numLoaded > tmrId { // This is the set that it's in, the index we need is tmrId - prevNum return timeCollection.Get(tmrId - prevNum), gdb.AllTypes[i], nil } prevNum = numLoaded } return nil, gime.TypeUnknown, errors.New("Unable to find timer with id: " + strconv.Itoa(tmrId)) }