Implemented total output
This commit is contained in:
parent
fda944ab17
commit
35cb75088e
1 changed files with 11 additions and 0 deletions
11
z/list.go
11
z/list.go
|
@ -5,8 +5,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var listTotalTime bool
|
||||||
|
|
||||||
var listCmd = &cobra.Command{
|
var listCmd = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list",
|
||||||
Short: "List activities",
|
Short: "List activities",
|
||||||
|
@ -46,10 +49,17 @@ var listCmd = &cobra.Command{
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
totalHours := decimal.NewFromInt(0);
|
||||||
for _, entry := range filteredEntries {
|
for _, entry := range filteredEntries {
|
||||||
|
duration := entry.Finish.Sub(entry.Begin)
|
||||||
|
durationDec := decimal.NewFromFloat(duration.Hours())
|
||||||
|
totalHours = totalHours.Add(durationDec)
|
||||||
fmt.Printf("%s\n", entry.GetOutput())
|
fmt.Printf("%s\n", entry.GetOutput())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if listTotalTime == true {
|
||||||
|
fmt.Printf("\nTOTAL: %s H\n\n", totalHours.StringFixed(2))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -60,6 +70,7 @@ func init() {
|
||||||
listCmd.Flags().StringVar(&until, "until", "", "Date/time to list until")
|
listCmd.Flags().StringVar(&until, "until", "", "Date/time to list until")
|
||||||
listCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be listed")
|
listCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be listed")
|
||||||
listCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be listed")
|
listCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be listed")
|
||||||
|
listCmd.Flags().BoolVar(&listTotalTime, "total", false, "Show total time of hours for listed activities")
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
database, err = InitDatabase()
|
database, err = InitDatabase()
|
||||||
|
|
Loading…
Reference in a new issue