diff --git a/internal/quic/qlog/json_writer.go b/internal/quic/qlog/json_writer.go index 3950ab42f6..b2fa3e03e5 100644 --- a/internal/quic/qlog/json_writer.go +++ b/internal/quic/qlog/json_writer.go @@ -157,6 +157,10 @@ func (w *jsonWriter) writeBoolField(name string, v bool) { // writeDuration writes a duration as milliseconds. func (w *jsonWriter) writeDuration(v time.Duration) { + if v < 0 { + w.buf.WriteByte('-') + v = -v + } fmt.Fprintf(&w.buf, "%d.%06d", v.Milliseconds(), v%time.Millisecond) } diff --git a/internal/quic/qlog/json_writer_test.go b/internal/quic/qlog/json_writer_test.go index 7ba5e17378..6da5566412 100644 --- a/internal/quic/qlog/json_writer_test.go +++ b/internal/quic/qlog/json_writer_test.go @@ -124,9 +124,10 @@ func TestJSONWriterBoolField(t *testing.T) { func TestJSONWriterDurationField(t *testing.T) { w := newTestJSONWriter() w.writeRecordStart() - w.writeDurationField("field", (10*time.Millisecond)+(2*time.Nanosecond)) + w.writeDurationField("field1", (10*time.Millisecond)+(2*time.Nanosecond)) + w.writeDurationField("field2", -((10 * time.Millisecond) + (2 * time.Nanosecond))) w.writeRecordEnd() - wantJSONRecord(t, w, `{"field":10.000002}`) + wantJSONRecord(t, w, `{"field1":10.000002,"field2":-10.000002}`) } func TestJSONWriterFloat64Field(t *testing.T) {