Skip to content

jsonpb: unexpected output for small negative google.protobuf.Duration #883

Closed
@AlekSi

Description

@AlekSi

What version of protobuf and what language are you using?
Version: v1.3.1

What did you do?
https://github.com/AlekSi/go-bug/tree/master/jsonpb

func TestDuration(t *testing.T) {
	d := -time.Nanosecond
	dp := ptypes.DurationProto(d)
	m := &jsonpb.Marshaler{}
	s, err := m.MarshalToString(dp)
	if err != nil {
		t.Fatal(err)
	}
	if s != `"-0.00000001s"` {
		t.Errorf("Unexpected result: %s", s)
	}
}

What did you expect to see?
"-0.00000001s"

What did you see instead?
Unexpected result: "0.-00000001s"

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions