Skip to content
Closed
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 src/time/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ func (t *Time) UnmarshalBinary(data []byte) error {
buf = buf[4:]
offset := int(int16(buf[1])|int16(buf[0])<<8) * 60
if version == timeBinaryVersionV2 {
offset += int(buf[2])
offset += int(int8(buf[2]))
}

*t = Time{}
Expand Down
23 changes: 23 additions & 0 deletions src/time/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,29 @@ func TestMarshalBinaryVersion2(t *testing.T) {
}
}

func TestMarshalBinaryVersion2Bugfix(t *testing.T) {
offsetSec := -5*3600 - 30*60 - 45 // -19845
loc := FixedZone("LMT", offsetSec)

t1 := Date(2024, 6, 15, 12, 0, 0, 0, loc)
b, err := t1.MarshalBinary()
if err != nil {
t.Errorf("Failed to Marshal, error = %v", err)
}

t2 := Time{}
err = t2.UnmarshalBinary(b)
if err != nil {
t.Errorf("Failed to Unmarshal, error = %v", err)
}

_, t1OriginOffset := t1.Zone()
_, t2OriginOffset := t2.Zone()
if t1OriginOffset != t2OriginOffset {
t.Errorf("The result offsetSec: %d after Unmarshal is not matched original offsetSec: %d", t2OriginOffset, t1OriginOffset)
}
}

func TestUnmarshalTextAllocations(t *testing.T) {
in := []byte(testdataRFC3339UTC) // short enough to be stack allocated
if allocs := testing.AllocsPerRun(100, func() {
Expand Down