Skip to content

Commit

Permalink
feat: print today's total times as well
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 committed Aug 10, 2021
1 parent 8ee89f4 commit 03767d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/ui/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func WriteProjectMarkdown(db *badger.DB, project string, w io.Writer) error {
_, _ = fmt.Fprintf(
w,
"> Total time **%s**, timed between **%s** and **%s**\n\n",
sumTasksTimes(tasks).Round(time.Second).String(),
sumTasksTimes(tasks, time.Time{}).Round(time.Second).String(),
tasks[len(tasks)-1].StartAt.Format("2006-01-02"),
tasks[0].EndAt.Format("2006-01-02"),
)
Expand Down
10 changes: 8 additions & 2 deletions internal/ui/project_timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ func (m projectTimerModel) Update(msg tea.Msg) (projectTimerModel, tea.Cmd) {

func (m projectTimerModel) View() string {
return secondaryForeground.Render("total: ") +
activeForegroundBold.Render(sumTasksTimes(m.tasks).Round(time.Second).String())
activeForegroundBold.Render(sumTasksTimes(m.tasks, time.Time{}).Round(time.Second).String()) +
separator +
secondaryForeground.Render("today: ") +
activeForegroundBold.Render(sumTasksTimes(m.tasks, time.Now().Truncate(time.Hour*24)).Round(time.Second).String())
}

// msgs and cmds
Expand All @@ -40,9 +43,12 @@ func updateProjectTimerCmd(tasks []model.Task) tea.Cmd {
}
}

func sumTasksTimes(tasks []model.Task) time.Duration {
func sumTasksTimes(tasks []model.Task, since time.Time) time.Duration {
d := time.Duration(0)
for _, t := range tasks {
if t.StartAt.Before(since) {
continue
}
z := t.EndAt
if z.IsZero() {
z = time.Now()
Expand Down

0 comments on commit 03767d2

Please sign in to comment.