fixed 'fetched in X seconds seconds'
All checks were successful
Run Integration Tests / test (push) Successful in 26s
All checks were successful
Run Integration Tests / test (push) Successful in 26s
This commit is contained in:
parent
06f8604779
commit
6445be87a9
9 changed files with 38 additions and 18 deletions
18
common.go
18
common.go
|
@ -107,3 +107,21 @@ func GetIconPath() (string, string) {
|
|||
// Default paths
|
||||
return "/static/images/icon.svg", "/static/images/icon.png"
|
||||
}
|
||||
|
||||
// FormatElapsedTime formats elapsed time as a string,
|
||||
// using:
|
||||
// - "> 0.01 ms" if under 49µs
|
||||
// - "0.xx ms" if under 1ms
|
||||
// - "xxx ms" if under 300ms
|
||||
// - "x.xx seconds" otherwise
|
||||
func FormatElapsedTime(elapsed time.Duration) string {
|
||||
if elapsed < 49*time.Microsecond {
|
||||
return fmt.Sprintf("> 0.01 %s", Translate("milliseconds"))
|
||||
} else if elapsed < time.Millisecond {
|
||||
ms := float64(elapsed.Microseconds()) / 1000.0
|
||||
return fmt.Sprintf("%.2f %s", ms, Translate("milliseconds"))
|
||||
} else if elapsed < 300*time.Millisecond {
|
||||
return fmt.Sprintf("%d %s", elapsed.Milliseconds(), Translate("milliseconds"))
|
||||
}
|
||||
return fmt.Sprintf("%.2f %s", elapsed.Seconds(), Translate("seconds"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue