2017-08-01 20:39:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"git.bullercodeworks.com/brian/gime"
|
|
|
|
)
|
|
|
|
|
2017-08-02 19:14:53 +00:00
|
|
|
// TimerToString takes a TimeEntry and gives a nicely formatted string
|
2017-08-01 20:39:24 +00:00
|
|
|
func TimerToString(t *gime.TimeEntry) string {
|
|
|
|
var ret string
|
2017-08-02 19:14:53 +00:00
|
|
|
var end string
|
2017-08-01 20:39:24 +00:00
|
|
|
if t.StartsToday() {
|
|
|
|
ret = t.GetStart().Format("15:04 - ")
|
2017-08-02 19:14:53 +00:00
|
|
|
end = "**:**"
|
2017-08-01 20:39:24 +00:00
|
|
|
} else {
|
|
|
|
ret = t.GetStart().Format("2006/01/02 15:04:05 - ")
|
2017-08-02 19:14:53 +00:00
|
|
|
end = "**:**:**"
|
2017-08-01 20:39:24 +00:00
|
|
|
}
|
|
|
|
if !t.GetEnd().IsZero() {
|
|
|
|
if t.EndsToday() {
|
2017-08-02 19:14:53 +00:00
|
|
|
end = t.GetEnd().Format("15:04")
|
2017-08-01 20:39:24 +00:00
|
|
|
} else {
|
2017-08-02 19:14:53 +00:00
|
|
|
end = t.GetEnd().Format("2006/01/02 15:04:05")
|
2017-08-01 20:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-02 19:14:53 +00:00
|
|
|
ret += end
|
2017-08-01 20:39:24 +00:00
|
|
|
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))
|
|
|
|
}
|