mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-22 02:21:36 +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
|
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) {
|
func printTrackedTimes(times []*gitea.TrackedTime, outputType string, from, until time.Time, printTotal bool) {
|
||||||
var outputValues [][]string
|
var outputValues [][]string
|
||||||
var totalDuration int64
|
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"),
|
t.Created.In(localLoc).Format("2006-01-02 15:04:05"),
|
||||||
"#" + strconv.FormatInt(t.Issue.Index, 10),
|
"#" + strconv.FormatInt(t.Issue.Index, 10),
|
||||||
t.UserName,
|
t.UserName,
|
||||||
time.Duration(1e9 * t.Time).String(),
|
formatDuration(t.Time, outputType),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if printTotal {
|
if printTotal {
|
||||||
outputValues = append(outputValues, []string{
|
outputValues = append(outputValues, []string{
|
||||||
"TOTAL", "", "", time.Duration(1e9 * totalDuration).String(),
|
"TOTAL", "", "", formatDuration(totalDuration, outputType),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user