Skip to content

Commit

Permalink
Finish prints Pomodoro duration
Browse files Browse the repository at this point in the history
  • Loading branch information
justincampbell committed Jan 18, 2021
1 parent 16e58ce commit ff7ed3f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## Unreleased

* `finish` prints the final duration.

## 0.3.0

* `start`, `stop`, and `break` hooks are now supported.
* tmux-color now accepts custom color flags.
* `tmux-color` now accepts custom color flags.
* Fix issue where `--directory` flag did not work properly.

## 0.2.1
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ $ pomodoro cancel
$ pomodoro status
```


### Finish a Pomodoro early (or late)

```
$ pomodoro status
12:34 🍅
1:23 🍅
$ pomodoro finish
23:37
$ pomodoro status
❗️🍅
```
Expand Down
12 changes: 12 additions & 0 deletions cmd/finish.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cmd

import (
"fmt"
"time"

"github.com/open-pomodoro/openpomodoro-cli/format"
"github.com/open-pomodoro/openpomodoro-cli/hook"
"github.com/spf13/cobra"
)
Expand All @@ -16,6 +20,14 @@ func init() {
}

func finishCmd(cmd *cobra.Command, args []string) error {
p, err := client.Pomodoro()
if err != nil {
return err
}

d := time.Now().Sub(p.StartTime)
fmt.Println(format.DurationAsTime(d))

if err := hook.Run(client, "stop"); err != nil {
return err
}
Expand Down
15 changes: 8 additions & 7 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func Format(s *openpomodoro.State, f string) string {
return result
}

// DurationAsTime returns a duration string.
func DurationAsTime(d time.Duration) string {
s := round(d.Seconds())
return fmt.Sprintf("%d:%02d", s/60, s%60)
}

func timeRemaining(exclaim bool) Formatter {
return func(s *openpomodoro.State) string {
d := s.Pomodoro.Remaining()
Expand All @@ -57,7 +63,7 @@ func timeRemaining(exclaim bool) Formatter {
}
}

return formatDurationAsTime(d)
return DurationAsTime(d)
}
}

Expand All @@ -75,7 +81,7 @@ func minutesRemaining(exclaim bool) Formatter {
}

func duration(s *openpomodoro.State) string {
return formatDurationAsTime(s.Pomodoro.Duration)
return DurationAsTime(s.Pomodoro.Duration)
}

func durationMinutes(s *openpomodoro.State) string {
Expand Down Expand Up @@ -111,11 +117,6 @@ func goalTotal(slash bool) Formatter {
}
}

func formatDurationAsTime(d time.Duration) string {
s := round(d.Seconds())
return fmt.Sprintf("%d:%02d", s/60, s%60)
}

func defaultString(i interface{}) string {
return fmt.Sprintf("%#v", i)
}
Expand Down

0 comments on commit ff7ed3f

Please sign in to comment.