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 {
|
func cmdPrintList(args []string) int {
|
||||||
loadActiveAndRecentTimeEntries()
|
loadActiveAndRecentTimeEntries()
|
||||||
// By default, list all entries ending today or still running
|
|
||||||
filter := func(t *gime.TimeEntry) bool {
|
useDefaultFilter := true
|
||||||
return t.EndsToday() || t.IsRunning()
|
|
||||||
}
|
var beg, end time.Time
|
||||||
/*
|
searchTags := []string{}
|
||||||
|
|
||||||
for _, opt := range args {
|
for _, opt := range args {
|
||||||
|
var tmpBeg, tmpEnd time.Time
|
||||||
|
|
||||||
// Do our best to figure out what timers the user wants to list
|
// Do our best to figure out what timers the user wants to list
|
||||||
var err error
|
var err error
|
||||||
var beg, end time.Time
|
|
||||||
if strings.Contains(opt, "-") {
|
if strings.Contains(opt, "-") {
|
||||||
|
useDefaultFilter = false
|
||||||
pts := strings.Split(opt, "-")
|
pts := strings.Split(opt, "-")
|
||||||
if len(pts[0]) > 0 {
|
if len(pts[0]) > 0 {
|
||||||
// This should be the starting date
|
// This should be the starting date
|
||||||
if beg, err = parseFuzzyTime(pts[0]); err != nil {
|
tmpBeg, err = parseFuzzyTime(pts[0])
|
||||||
fmt.Println("Start date:", err.Error())
|
if err != nil {
|
||||||
return 1
|
// We couldn't parse it as a time,
|
||||||
|
// Probably this is just a tag
|
||||||
|
searchTags = append(searchTags, opt)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(pts[1]) > 0 {
|
if len(pts[1]) > 0 {
|
||||||
// This should be the ending date
|
// This should be the ending date
|
||||||
if end, err = parseFuzzyTime(pts[1]); err != nil {
|
tmpEnd, err = parseFuzzyTime(pts[1])
|
||||||
fmt.Println("End date:", err.Error())
|
if err != nil {
|
||||||
return 1
|
searchTags = append(searchTags, opt)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Tag filters
|
||||||
|
searchTags = append(searchTags, opt)
|
||||||
|
}
|
||||||
|
if !tmpBeg.IsZero() || !tmpEnd.IsZero() {
|
||||||
|
beg, end = tmpBeg, tmpEnd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if end.IsZero() {
|
if end.IsZero() {
|
||||||
end = time.Now()
|
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"))
|
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)
|
str = " " + strings.Replace(str, "\n", "\n ", -1)
|
||||||
fmt.Println(str)
|
fmt.Println(str)
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
Reference in New Issue
Block a user