54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"strconv"
|
||
|
|
||
|
"git.bullercodeworks.com/brian/gime"
|
||
|
)
|
||
|
|
||
|
func TimerToString(t *gime.TimeEntry) string {
|
||
|
var ret string
|
||
|
if t.StartsToday() {
|
||
|
ret = t.GetStart().Format("15:04 - ")
|
||
|
} else {
|
||
|
ret = t.GetStart().Format("2006/01/02 15:04:05 - ")
|
||
|
}
|
||
|
if !t.GetEnd().IsZero() {
|
||
|
if t.EndsToday() {
|
||
|
ret += t.GetEnd().Format("15:04")
|
||
|
} else {
|
||
|
ret += t.GetEnd().Format("2006/01/02 15:04:05")
|
||
|
}
|
||
|
} else {
|
||
|
ret += "**:**:**"
|
||
|
}
|
||
|
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))
|
||
|
}
|