feat: calculate duration

This commit is contained in:
Jason Song
2023-01-05 16:19:08 +08:00
parent c510fdbcf1
commit a4b2cf2426
8 changed files with 82 additions and 39 deletions

View File

@ -10,8 +10,10 @@ import (
"errors"
"fmt"
"io"
"time"
auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
)
@ -67,3 +69,16 @@ func (indexes *LogIndexes) ToDB() ([]byte, error) {
}
return buf[:i], nil
}
var timeSince = time.Since
func calculateDuration(started, stopped timeutil.TimeStamp, status Status) time.Duration {
if started == 0 {
return 0
}
s := started.AsTime()
if status.IsDone() {
return stopped.AsTime().Sub(s)
}
return timeSince(s).Truncate(time.Second)
}