Skip to content

Commit

Permalink
Implemented projects/tasks structure listing; this implements #1 part…
Browse files Browse the repository at this point in the history
…ially
  • Loading branch information
mrusme committed Oct 20, 2020
1 parent 59c05b1 commit 2d7dbdd
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,43 @@ zeit finish --begin 16:00

### List tracked activity

```sh
zeit list --help
```

#### Examples:

List all tracked activities:

```sh
zeit list
```

List all tracked activities since a specific date/time:

```sh
zeit list --since "2020-10-14T00:00:01+01:00"
```

List all tracked activities and add the total hours:

```sh
zeit list --total
```

List only projects and tasks (relational):

```sh
zeit list --only-projects-and-tasks
```

List only projects and tasks (relational) that were tracked since a specific
date/time:

```sh
zeit list --only-projects-and-tasks --since "2020-10-14T00:00:01+01:00"
```


### Display/update activity

Expand Down
6 changes: 6 additions & 0 deletions z/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"
"fmt"
"github.com/gookit/color"
"github.com/shopspring/decimal"
)

type Entry struct {
Expand Down Expand Up @@ -128,6 +129,11 @@ func (entry *Entry) GetOutputForTrack(isRunning bool, wasRunning bool) (string)
return fmt.Sprintf("%s %s task%s\n", CharTrack, outputPrefix, outputSuffix)
}

func (entry *Entry) GetDuration() (decimal.Decimal) {
duration := entry.Finish.Sub(entry.Begin)
return decimal.NewFromFloat(duration.Hours())
}

func (entry *Entry) GetOutputForFinish() (string) {
var outputSuffix string = ""

Expand Down
32 changes: 29 additions & 3 deletions z/listCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

var listTotalTime bool
var listOnlyProjectsAndTasks bool

var listCmd = &cobra.Command{
Use: "list",
Expand Down Expand Up @@ -49,11 +50,35 @@ var listCmd = &cobra.Command{
os.Exit(1)
}

if listOnlyProjectsAndTasks == true {
var projectsAndTasks = make(map[string]map[string]bool)

for _, filteredEntry := range filteredEntries {
taskMap, ok := projectsAndTasks[filteredEntry.Project]

if !ok {
taskMap = make(map[string]bool)
projectsAndTasks[filteredEntry.Project] = taskMap
}

taskMap[filteredEntry.Task] = true
projectsAndTasks[filteredEntry.Project] = taskMap
}

for project, _ := range projectsAndTasks {
fmt.Printf("%s %s\n", CharMore, project)

for task, _ := range projectsAndTasks[project] {
fmt.Printf("%*s└── %s\n", 1, " ", task)
}
}

return
}

totalHours := decimal.NewFromInt(0);
for _, entry := range filteredEntries {
duration := entry.Finish.Sub(entry.Begin)
durationDec := decimal.NewFromFloat(duration.Hours())
totalHours = totalHours.Add(durationDec)
totalHours = totalHours.Add(entry.GetDuration())
fmt.Printf("%s\n", entry.GetOutput(false))
}

Expand All @@ -71,6 +96,7 @@ func init() {
listCmd.Flags().StringVarP(&project, "project", "p", "", "Project 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")
listCmd.Flags().BoolVar(&listOnlyProjectsAndTasks, "only-projects-and-tasks", false, "Only list projects and their tasks, no entries")

var err error
database, err = InitDatabase()
Expand Down
1 change: 1 addition & 0 deletions z/rootCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const(
CharErase = " ◀"
CharError = " ▲"
CharInfo = " ●"
CharMore = " ◆"
)

var rootCmd = &cobra.Command{
Expand Down

0 comments on commit 2d7dbdd

Please sign in to comment.