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

util/timeutil: Ensure exponents are never encoded into the output String() #4123

Merged
merged 1 commit into from
Nov 8, 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
2 changes: 1 addition & 1 deletion util/timeutil/isoduration.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (dur ISODuration) String() string {
sec := dur.SecondPart
// round to microseconds
sec = math.Round(sec*1e6) / 1e6
fmt.Fprintf(&b, "%gS", sec)
fmt.Fprintf(&b, "%sS", strconv.FormatFloat(sec, 'f', -1, 64))
}

return b.String()
Expand Down
3 changes: 2 additions & 1 deletion util/timeutil/isoduration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func TestISODuration_String(t *testing.T) {
check("P1D", ISODuration{DayPart: 1})
check("PT1H", ISODuration{HourPart: 1})
check("P1YT0.1S", ISODuration{YearPart: 1, SecondPart: 0.1})
check("P1YT0.123457S", ISODuration{YearPart: 1, SecondPart: 0.1234567}) // Note: rounded to 6 decimal places, so the 6th digit is 7 instead of 6.
check("P1YT0.000076S", ISODuration{YearPart: 1, SecondPart: 7.5809468881749e-05}) // Ensure we don't print an exponent.

check("P1Y2M3W4DT5H6M7S", ISODuration{
YearPart: 1,
Expand All @@ -39,7 +41,6 @@ func TestISODuration_String(t *testing.T) {
}

func TestParseISODuration(t *testing.T) {

check := func(desc string, iso string, exp ISODuration) {
t.Helper()

Expand Down
Loading