Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix humanizeDurationSeconds func #75

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ func humanizeDurationSeconds(seconds float64) string {
for n := duration / unit; n >= unit; n /= unit {
div *= unit
exp++
if exp >= len(units)-1 {
break
}
}

return fmt.Sprintf("%.2f%s",
Expand Down
17 changes: 17 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,20 @@ func TestHeadersParsing(t *testing.T) {
}
}
}

func TestHumanizeDurationSeconds(t *testing.T) {
requestTime := humanizeDurationSeconds(6000)
if requestTime != "6000.00s" {
t.Errorf("Wrong requestTime: %q", requestTime)
}

requestTime = humanizeDurationSeconds(0.05)
if requestTime != "50.00ms" {
t.Errorf("Wrong requestTime: %q", requestTime)
}

requestTime = humanizeDurationSeconds(99999999)
if requestTime != "99999999.00s" {
t.Errorf("Wrong requestTime: %q", requestTime)
}
}
Loading