Skip to content

Commit

Permalink
(feat): formating duration as h:mm:ss (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassabreu authored May 22, 2020
1 parent a76d51b commit 0c946f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## Changed

- printing duration as "h:mm:ss" instead of the Go's default format,
because is more user and sheet applications friendly.

## [v0.3.1] - 2020-04-01

## Fixed
Expand Down
10 changes: 7 additions & 3 deletions reports/timeEntry.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TimeEntriesPrint(timeEntries []dto.TimeEntry, w io.Writer) error {
t.ID,
t.TimeInterval.Start.In(time.Local).Format("15:04:05"),
end.In(time.Local).Format("15:04:05"),
fmt.Sprintf("%-8v", end.Sub(t.TimeInterval.Start)),
durationToString(end.Sub(t.TimeInterval.Start)),
projectName,
t.Description,
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func TimeEntriesCSVPrint(timeEntries []dto.TimeEntry, out io.Writer) error {
p = *te.Project
}

end := te.TimeInterval.Start
end := time.Now()
if te.TimeInterval.End != nil {
end = *te.TimeInterval.End
}
Expand All @@ -141,7 +141,7 @@ func TimeEntriesCSVPrint(timeEntries []dto.TimeEntry, out io.Writer) error {
p.Name,
format(&te.TimeInterval.Start),
format(te.TimeInterval.End),
fmt.Sprintf("%-8v", end.Sub(te.TimeInterval.Start)),
durationToString(end.Sub(te.TimeInterval.Start)),
te.User.ID,
te.User.Email,
te.User.Name,
Expand Down Expand Up @@ -211,3 +211,7 @@ func TimeEntryPrintWithTemplate(format string) func(*dto.TimeEntry, io.Writer) e
return fn(entries, w)
}
}

func durationToString(d time.Duration) string {
return fmt.Sprintf("%d:%02d:%02d", int64(d.Hours()), int64(d.Minutes())%60, int64(d.Seconds())%60)
}

0 comments on commit 0c946f4

Please sign in to comment.