Fixed indentation
This commit is contained in:
parent
e4ffc80b04
commit
6783e5d082
3 changed files with 102 additions and 102 deletions
|
@ -131,7 +131,7 @@ func (entry *Entry) GetOutputForTrack(isRunning bool, wasRunning bool) (string)
|
|||
|
||||
func (entry *Entry) GetDuration() (decimal.Decimal) {
|
||||
duration := entry.Finish.Sub(entry.Begin)
|
||||
if (duration < 0) {
|
||||
if (duration < 0) {
|
||||
duration = time.Now().Sub(entry.Begin)
|
||||
}
|
||||
return decimal.NewFromFloat(duration.Hours())
|
||||
|
@ -169,9 +169,9 @@ func (entry *Entry) GetOutput(full bool) (string) {
|
|||
}
|
||||
|
||||
trackDiff := entryFinish.Sub(entry.Begin)
|
||||
taskDuration := fmtDuration(trackDiff)
|
||||
taskDuration := fmtDuration(trackDiff)
|
||||
if full == false {
|
||||
|
||||
|
||||
output = fmt.Sprintf("%s %s on %s from %s to %s (%sh) %s",
|
||||
color.FgGray.Render(entry.ID),
|
||||
color.FgLightWhite.Render(entry.Task),
|
||||
|
|
170
z/listCmd.go
170
z/listCmd.go
|
@ -1,12 +1,12 @@
|
|||
package z
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var listTotalTime bool
|
||||
|
@ -15,102 +15,102 @@ var appendProjectIDToTask bool
|
|||
|
||||
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List activities",
|
||||
Long: "List all tracked activities.",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
user := GetCurrentUser()
|
||||
Use: "list",
|
||||
Short: "List activities",
|
||||
Long: "List all tracked activities.",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
user := GetCurrentUser()
|
||||
|
||||
entries, err := database.ListEntries(user)
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
entries, err := database.ListEntries(user)
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var sinceTime time.Time
|
||||
var untilTime time.Time
|
||||
var sinceTime time.Time
|
||||
var untilTime time.Time
|
||||
|
||||
if since != "" {
|
||||
sinceTime, err = time.Parse(time.RFC3339, since)
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if since != "" {
|
||||
sinceTime, err = time.Parse(time.RFC3339, since)
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
if until != "" {
|
||||
untilTime, err = time.Parse(time.RFC3339, until)
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if until != "" {
|
||||
untilTime, err = time.Parse(time.RFC3339, until)
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
var filteredEntries []Entry
|
||||
filteredEntries, err = GetFilteredEntries(entries, project, task, sinceTime, untilTime)
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var filteredEntries []Entry
|
||||
filteredEntries, err = GetFilteredEntries(entries, project, task, sinceTime, untilTime)
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if listOnlyProjectsAndTasks == true {
|
||||
var projectsAndTasks = make(map[string]map[string]bool)
|
||||
if listOnlyProjectsAndTasks == true {
|
||||
var projectsAndTasks = make(map[string]map[string]bool)
|
||||
|
||||
for _, filteredEntry := range filteredEntries {
|
||||
taskMap, ok := projectsAndTasks[filteredEntry.Project]
|
||||
for _, filteredEntry := range filteredEntries {
|
||||
taskMap, ok := projectsAndTasks[filteredEntry.Project]
|
||||
|
||||
if !ok {
|
||||
taskMap = make(map[string]bool)
|
||||
projectsAndTasks[filteredEntry.Project] = taskMap
|
||||
}
|
||||
if !ok {
|
||||
taskMap = make(map[string]bool)
|
||||
projectsAndTasks[filteredEntry.Project] = taskMap
|
||||
}
|
||||
|
||||
taskMap[filteredEntry.Task] = true
|
||||
projectsAndTasks[filteredEntry.Project] = taskMap
|
||||
}
|
||||
taskMap[filteredEntry.Task] = true
|
||||
projectsAndTasks[filteredEntry.Project] = taskMap
|
||||
}
|
||||
|
||||
for project, _ := range projectsAndTasks {
|
||||
fmt.Printf("%s %s\n", CharMore, project)
|
||||
for project, _ := range projectsAndTasks {
|
||||
fmt.Printf("%s %s\n", CharMore, project)
|
||||
|
||||
for task, _ := range projectsAndTasks[project] {
|
||||
if appendProjectIDToTask == true {
|
||||
fmt.Printf("%*s└── %s [%s]\n", 1, " ", task, project)
|
||||
} else {
|
||||
fmt.Printf("%*s└── %s\n", 1, " ", task)
|
||||
}
|
||||
}
|
||||
}
|
||||
for task, _ := range projectsAndTasks[project] {
|
||||
if appendProjectIDToTask == true {
|
||||
fmt.Printf("%*s└── %s [%s]\n", 1, " ", task, project)
|
||||
} else {
|
||||
fmt.Printf("%*s└── %s\n", 1, " ", task)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
totalHours := decimal.NewFromInt(0)
|
||||
for _, entry := range filteredEntries {
|
||||
totalHours = totalHours.Add(entry.GetDuration())
|
||||
fmt.Printf("%s\n", entry.GetOutput(false))
|
||||
}
|
||||
totalHours := decimal.NewFromInt(0)
|
||||
for _, entry := range filteredEntries {
|
||||
totalHours = totalHours.Add(entry.GetDuration())
|
||||
fmt.Printf("%s\n", entry.GetOutput(false))
|
||||
}
|
||||
|
||||
if listTotalTime == true {
|
||||
fmt.Printf("\nTOTAL: %s H\n\n", fmtHours(totalHours));
|
||||
}
|
||||
return
|
||||
},
|
||||
if listTotalTime == true {
|
||||
fmt.Printf("\nTOTAL: %s H\n\n", fmtHours(totalHours));
|
||||
}
|
||||
return
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(listCmd)
|
||||
listCmd.Flags().StringVar(&since, "since", "", "Date/time to start the list from")
|
||||
listCmd.Flags().StringVar(&until, "until", "", "Date/time to list until")
|
||||
listCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be listed")
|
||||
listCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be listed")
|
||||
listCmd.Flags().BoolVar(&fractional, "decimal", false, "Show fractional hours in decimal format instead of minutes")
|
||||
listCmd.Flags().BoolVar(&listTotalTime, "total", false, "Show total time of hours for listed activities")
|
||||
listCmd.Flags().BoolVar(&listOnlyProjectsAndTasks, "only-projects-and-tasks", false, "Only list projects and their tasks, no entries")
|
||||
listCmd.Flags().BoolVar(&appendProjectIDToTask, "append-project-id-to-task", false, "Append project ID to tasks in the list")
|
||||
rootCmd.AddCommand(listCmd)
|
||||
listCmd.Flags().StringVar(&since, "since", "", "Date/time to start the list from")
|
||||
listCmd.Flags().StringVar(&until, "until", "", "Date/time to list until")
|
||||
listCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be listed")
|
||||
listCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be listed")
|
||||
listCmd.Flags().BoolVar(&fractional, "decimal", false, "Show fractional hours in decimal format instead of minutes")
|
||||
listCmd.Flags().BoolVar(&listTotalTime, "total", false, "Show total time of hours for listed activities")
|
||||
listCmd.Flags().BoolVar(&listOnlyProjectsAndTasks, "only-projects-and-tasks", false, "Only list projects and their tasks, no entries")
|
||||
listCmd.Flags().BoolVar(&appendProjectIDToTask, "append-project-id-to-task", false, "Append project ID to tasks in the list")
|
||||
|
||||
var err error
|
||||
database, err = InitDatabase()
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var err error
|
||||
database, err = InitDatabase()
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
28
z/util.go
28
z/util.go
|
@ -1,28 +1,28 @@
|
|||
package z
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
var fractional bool
|
||||
|
||||
func fmtDuration(dur time.Duration) (string) {
|
||||
return fmtHours(decimal.NewFromFloat(dur.Hours()))
|
||||
return fmtHours(decimal.NewFromFloat(dur.Hours()))
|
||||
}
|
||||
|
||||
func fmtHours(hours decimal.Decimal) (string) {
|
||||
if fractional {
|
||||
return hours.StringFixed(2)
|
||||
} else {
|
||||
return fmt.Sprintf(
|
||||
"%s:%02s",
|
||||
hours.Floor(), // hours
|
||||
if fractional {
|
||||
return hours.StringFixed(2)
|
||||
} else {
|
||||
return fmt.Sprintf(
|
||||
"%s:%02s",
|
||||
hours.Floor(), // hours
|
||||
hours.Sub(hours.Floor()).
|
||||
Mul(decimal.NewFromFloat(.6)).
|
||||
Mul(decimal.NewFromInt(100)).
|
||||
Floor())
|
||||
}
|
||||
Mul(decimal.NewFromFloat(.6)).
|
||||
Mul(decimal.NewFromInt(100)).
|
||||
Floor())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue