Skip to content

Commit 1e59a7e

Browse files
committed
quic/qlog: correctly write negative durations
"-10.000001", not "10.-000001". Change-Id: I84f6487bad15ab3a190e73e655236376b1781e85 Reviewed-on: https://go-review.googlesource.com/c/net/+/545576 Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent b0eb4d6 commit 1e59a7e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

internal/quic/qlog/json_writer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ func (w *jsonWriter) writeBoolField(name string, v bool) {
157157

158158
// writeDuration writes a duration as milliseconds.
159159
func (w *jsonWriter) writeDuration(v time.Duration) {
160+
if v < 0 {
161+
w.buf.WriteByte('-')
162+
v = -v
163+
}
160164
fmt.Fprintf(&w.buf, "%d.%06d", v.Milliseconds(), v%time.Millisecond)
161165
}
162166

internal/quic/qlog/json_writer_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ func TestJSONWriterBoolField(t *testing.T) {
124124
func TestJSONWriterDurationField(t *testing.T) {
125125
w := newTestJSONWriter()
126126
w.writeRecordStart()
127-
w.writeDurationField("field", (10*time.Millisecond)+(2*time.Nanosecond))
127+
w.writeDurationField("field1", (10*time.Millisecond)+(2*time.Nanosecond))
128+
w.writeDurationField("field2", -((10 * time.Millisecond) + (2 * time.Nanosecond)))
128129
w.writeRecordEnd()
129-
wantJSONRecord(t, w, `{"field":10.000002}`)
130+
wantJSONRecord(t, w, `{"field1":10.000002,"field2":-10.000002}`)
130131
}
131132

132133
func TestJSONWriterFloat64Field(t *testing.T) {

0 commit comments

Comments
 (0)