Filter list by time & tags
This commit is contained in:
parent
4a5524ffb5
commit
1096c4024f
@ -139,46 +139,78 @@ func cmdPrintHelp(args []string) int {
|
||||
|
||||
func cmdPrintList(args []string) int {
|
||||
loadActiveAndRecentTimeEntries()
|
||||
// By default, list all entries ending today or still running
|
||||
filter := func(t *gime.TimeEntry) bool {
|
||||
return t.EndsToday() || t.IsRunning()
|
||||
}
|
||||
/*
|
||||
|
||||
useDefaultFilter := true
|
||||
|
||||
var beg, end time.Time
|
||||
searchTags := []string{}
|
||||
|
||||
for _, opt := range args {
|
||||
var tmpBeg, tmpEnd time.Time
|
||||
|
||||
// Do our best to figure out what timers the user wants to list
|
||||
var err error
|
||||
var beg, end time.Time
|
||||
if strings.Contains(opt, "-") {
|
||||
useDefaultFilter = false
|
||||
pts := strings.Split(opt, "-")
|
||||
if len(pts[0]) > 0 {
|
||||
// This should be the starting date
|
||||
if beg, err = parseFuzzyTime(pts[0]); err != nil {
|
||||
fmt.Println("Start date:", err.Error())
|
||||
return 1
|
||||
tmpBeg, err = parseFuzzyTime(pts[0])
|
||||
if err != nil {
|
||||
// We couldn't parse it as a time,
|
||||
// Probably this is just a tag
|
||||
searchTags = append(searchTags, opt)
|
||||
continue
|
||||
}
|
||||
}
|
||||
if len(pts[1]) > 0 {
|
||||
// This should be the ending date
|
||||
if end, err = parseFuzzyTime(pts[1]); err != nil {
|
||||
fmt.Println("End date:", err.Error())
|
||||
return 1
|
||||
tmpEnd, err = parseFuzzyTime(pts[1])
|
||||
if err != nil {
|
||||
searchTags = append(searchTags, opt)
|
||||
continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Tag filters
|
||||
searchTags = append(searchTags, opt)
|
||||
}
|
||||
if !tmpBeg.IsZero() || !tmpEnd.IsZero() {
|
||||
beg, end = tmpBeg, tmpEnd
|
||||
}
|
||||
}
|
||||
if end.IsZero() {
|
||||
end = time.Now()
|
||||
}
|
||||
} else if strings.HasPrefix(opt, "week") {
|
||||
|
||||
} else if strings.HasPrefix(opt, "biweek") {
|
||||
// By default, list all entries ending today or still running
|
||||
defaultFilter := func(t *gime.TimeEntry) bool {
|
||||
return t.EndsToday() || t.IsRunning()
|
||||
}
|
||||
|
||||
timeSpanFilter := func(t *gime.TimeEntry) bool {
|
||||
return t.GetStart().After(beg) && t.GetEnd().Before(end)
|
||||
}
|
||||
fmt.Println(beg, " - ", end)
|
||||
tagFilter := func(t *gime.TimeEntry) bool {
|
||||
for i := range searchTags {
|
||||
if !t.HasTag(searchTags[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
compoundFilter := func(t *gime.TimeEntry) bool {
|
||||
// If we didn't get any other filter specifications, just use the default
|
||||
if useDefaultFilter {
|
||||
return defaultFilter(t)
|
||||
}
|
||||
// Otherwise we want to filter timespan and tags
|
||||
return timeSpanFilter(t) && tagFilter(t)
|
||||
}
|
||||
return 0
|
||||
*/
|
||||
|
||||
fmt.Println(time.Now().Format("2006/01/02"))
|
||||
str := TimerCollectionToString(filterTimerCollection(timeEntries, filter))
|
||||
str := TimerCollectionToString(filterTimerCollection(timeEntries, compoundFilter))
|
||||
str = " " + strings.Replace(str, "\n", "\n ", -1)
|
||||
fmt.Println(str)
|
||||
return 0
|
||||
|
Loading…
Reference in New Issue
Block a user