mirror of
https://gitea.com/gitea/tea.git
synced 2024-12-22 09:05:06 +01:00
times: format duration as seconds for machine-readable outputs (#168)
times: format duration as seconds for machine-readable outputs Co-authored-by: Norwin Roosen <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/168 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: mrsdizzie <info@mrsdizzie.com>
This commit is contained in:
parent
25a7e85c1c
commit
9ae7196a50
13
cmd/times.go
13
cmd/times.go
@ -101,6 +101,15 @@ func runTrackedTimes(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func formatDuration(seconds int64, outputType string) string {
|
||||
switch outputType {
|
||||
case "yaml":
|
||||
case "csv":
|
||||
return fmt.Sprint(seconds)
|
||||
}
|
||||
return time.Duration(1e9 * seconds).String()
|
||||
}
|
||||
|
||||
func printTrackedTimes(times []*gitea.TrackedTime, outputType string, from, until time.Time, printTotal bool) {
|
||||
var outputValues [][]string
|
||||
var totalDuration int64
|
||||
@ -126,14 +135,14 @@ func printTrackedTimes(times []*gitea.TrackedTime, outputType string, from, unti
|
||||
t.Created.In(localLoc).Format("2006-01-02 15:04:05"),
|
||||
"#" + strconv.FormatInt(t.Issue.Index, 10),
|
||||
t.UserName,
|
||||
time.Duration(1e9 * t.Time).String(),
|
||||
formatDuration(t.Time, outputType),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
if printTotal {
|
||||
outputValues = append(outputValues, []string{
|
||||
"TOTAL", "", "", time.Duration(1e9 * totalDuration).String(),
|
||||
"TOTAL", "", "", formatDuration(totalDuration, outputType),
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user