Working on it

This commit is contained in:
Brian Buller 2017-08-02 14:14:53 -05:00
parent 0127427d18
commit 3d420d20ba
6 changed files with 75 additions and 27 deletions

View File

@ -7,22 +7,25 @@ import (
"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() {
ret += t.GetEnd().Format("15:04")
end = t.GetEnd().Format("15:04")
} else {
ret += t.GetEnd().Format("2006/01/02 15:04:05")
end = t.GetEnd().Format("2006/01/02 15:04:05")
}
} else {
ret += "**:**:**"
}
ret += end
tags := t.GetTags()
if tags.Length() > 0 {
ret += " [ "

View File

@ -47,6 +47,8 @@ func main() {
ret = cmdPrintStatus()
case "start":
ret = cmdStartTimer(parms[1:])
case "switch":
ret = cmdSwitchTimer(parms[1:])
case "end", "stop":
ret = cmdStopTimer(parms[1:])
case "list", "ls":
@ -118,7 +120,6 @@ func loadActiveTimeEntries() {
}
func cmdPrintList(args []string) int {
/*
var err error
loadActiveTimeEntries()
// By default, list all entries for today
@ -127,7 +128,6 @@ func cmdPrintList(args []string) int {
if len(args) < 1 {
}
*/
return 0
}
@ -216,6 +216,10 @@ func initialize() {
" If the first sub-argument given looks like a time,",
" the timer will be stopped then (past or future).",
}
validOperations["switch"] = []string{
"switch [tags ...] - Stop all currently running timers and start a new",
" one with the given tags",
}
// Load the Config
cfg, err = userConfig.NewConfig(AppName)

View File

@ -10,9 +10,23 @@ import (
// switchTimer performs a stop on any currently running timers
// and starts a new timer with the given arguments
func switchTimer(args []string) int {
func cmdSwitchTimer(args []string) int {
loadActiveTimeEntries()
return 0
tm := time.Now()
if activeTimeEntries.Length() > 0 {
fmt.Println("Stopped Timers:")
}
for i := 0; i < activeTimeEntries.Length(); i++ {
tmr := activeTimeEntries.Get(i)
tmr.SetEnd(tm)
if err := gdb.UpdateTimeEntry(tmr); err != nil {
fmt.Println(err.Error())
return 1
}
fmt.Println(" " + TimerToString(tmr))
}
fmt.Println("Started Timer:")
return cmdStartTimer(args)
}
// cmdStartTimer takes a list of arguments and returns the return code
@ -40,7 +54,6 @@ func cmdStartTimer(args []string) int {
if tagStart < len(args) {
timerArgs = args[tagStart:]
}
fmt.Println(tm)
tc := new(gime.TagCollection)
for i := range timerArgs {
tc.Push(timerArgs[i])
@ -53,6 +66,7 @@ func cmdStartTimer(args []string) int {
fmt.Println(err)
return 1
}
fmt.Println(" " + TimerToString(entry))
return 0
}

View File

@ -3,6 +3,7 @@ package gime
import (
"errors"
"fmt"
"time"
"github.com/br0xen/boltease"
)
@ -23,6 +24,8 @@ const (
TypeRecent = "recent"
TypeArchive = "archive"
TypeUnknown = "unknown" // Not really a type, used for searches and stuff
ArchiveDays = time.Hour * 24 * 90 // Archive anything older than 90 days
)
// Load Database returns a database loaded off the files given

View File

@ -34,8 +34,8 @@ func (gdb *GimeDB) SaveTimeEntry(te *TimeEntry) error {
tp = TypeCurrent
} else {
// We have an end time. Does this entry go in 'recent' or 'archive'
// We shove times that happened 30 days ago into 'archive'
if time.Since(te.end) > (time.Hour * 24 * 30) {
// We shove times that happened 90 days ago (~1/4 year) into 'archive'
if time.Since(te.end) > (time.Hour * 24 * 90) {
tp = TypeArchive
}
}
@ -90,6 +90,27 @@ func (gdb *GimeDB) RemoveTimeEntry(uuid string) error {
return useDb.DeleteBucket([]string{tp}, fndEntry.start.Format(time.RFC3339))
}
// GetTimeEntriesInRange takes two times and returns all time entries that occur
// on or between those dates
func (gdb *GimeDB) GetTimeEntriesInRange(st time.Time, end time.Time) *TimeEntryCollection {
var err error
ret := new(TimeEntryCollection)
if time.Since(st) > ArchiveDays {
if err = gdb.openArchiveDatabase(); err != nil {
return ret
}
defer gdb.closeArchiveDatabase()
var sttimes []string
if sttimes, err = gdb.db.GetBucketList([]string{TypeArchive}); err != nil {
return ret
}
for i := len(sttimes) - 1; i > 0; i-- {
}
}
return ret
}
// dbGetAllTimeEntries gets all time entries of a specific type
// tp can be:
// TypeCurrent = "current"
@ -124,7 +145,7 @@ func (gdb *GimeDB) dbGetAllTimeEntries(tp string) []TimeEntry {
return ret
}
// dbGetTimeEntry pulls a time entry of type tp with the given id
// dbGetTimeEntry pulls a time entry of type tp with the given start time
// from the db and returns it.
func (gdb *GimeDB) dbGetTimeEntry(tp, sttm string) (*TimeEntry, error) {
var ret *TimeEntry

View File

@ -97,24 +97,27 @@ func (t *TimeEntry) RemoveTag(s string) {
}
}
// Equals tests if the passed time entry is the same
// as the one that we're calling it on.
func (t *TimeEntry) Equals(tst *TimeEntry) bool {
return t.uuid == tst.uuid
}
// StartsToday returns if the timer's start time is today
func (t *TimeEntry) StartsToday() bool {
if time.Since(t.GetStart()).Hours() > 24 {
return false
}
return t.GetStart().Day() == time.Now().Day()
currTime := time.Now()
dur := currTime.Hour()*time.Hour + currTime.Minute()*time.Minute
return time.Since(t.GetStart()) < dur
}
// StartsToday returns if the timer's end time is today
func (t *TimeEntry) EndsToday() bool {
if time.Since(t.GetEnd()).Hours() > 24 {
return false
}
return t.GetEnd().Day() == time.Now().Day()
currTime := time.Now()
dur := currTime.Hour()*time.Hour + currTime.Minute()*time.Minute
return time.Since(t.GetEnd()) < dur
}
// String formats a string of the time entry
func (t *TimeEntry) String() string {
var ret string
ret = t.GetStart().Format(time.RFC3339)