commit d9c509cc818a9ee0d92197746b13455c978a7992
parent c89a7084641ea1de118d935b3ca4cc307c7ed3fb
Author: Tomas Nemec <nemi@skaut.cz>
Date: Fri, 10 Feb 2023 19:43:59 +0100
feat: list duration
Diffstat:
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/command.go b/command.go
@@ -8,6 +8,7 @@ import (
"path"
"path/filepath"
"strings"
+ "time"
"gtms.dev/tme/tme"
)
@@ -195,11 +196,18 @@ func formatEntries(group tme.Group, entryTime *tme.Time) {
}
for _, entry := range entries {
- switch v := entry.(type) {
+
+ groupPath := group.Path
+ duration := entry.Duration().Round(time.Second)
+
+ switch e := entry.(type) {
case tme.FinalEntry:
- fmt.Printf("%v\t%v\t%v\n", group.EntryPath(entry), v.Start.Format(tme.TimeLayout), v.Stop.Format(tme.TimeLayout))
+ start := e.Start.Format(tme.TimeLayout)
+ stop := e.Stop.Format(tme.TimeLayout)
+ fmt.Printf("%v\t%v\t%v\t%v\n", groupPath, start, stop, duration)
case tme.RunningEntry:
- fmt.Printf("%v\t%v\t%s\n", group.EntryPath(entry), v.Start.Format(tme.TimeLayout), "running")
+ start := e.Start.Format(tme.TimeLayout)
+ fmt.Printf("%v\t%v\t%s\t%v\n", groupPath, start, "running", duration)
}
}
}
diff --git a/tme/entry.go b/tme/entry.go
@@ -13,6 +13,7 @@ type Entry interface {
Data() string
FileName() string
FullPath(group Group) string
+ Duration() time.Duration
}
func NewEntryFromPath(entryPath string, entryTime *Time) (Entry, error) {
@@ -102,6 +103,10 @@ func (e FinalEntry) Exists(group Group) bool {
return false
}
+func (e FinalEntry) Duration() time.Duration {
+ return e.Stop.Sub(e.Start)
+}
+
type RunningEntry struct {
Start time.Time
}
@@ -153,3 +158,7 @@ func (e RunningEntry) Exists(group Group) bool {
func (e RunningEntry) Stop(stop time.Time) (FinalEntry, error) {
return NewFinalEntry(e.Start, stop)
}
+
+func (e RunningEntry) Duration() time.Duration {
+ return time.Since(e.Start)
+}
diff --git a/tme/time.go b/tme/time.go
@@ -43,3 +43,7 @@ func (et *Time) ParseEntry(raw string) (time.Time, error) {
et.context.Location(),
), err
}
+
+func (et *Time) Duration(start time.Time, stop time.Time) time.Duration {
+ return start.Sub(stop)
+}