Skip to content

Commit c6a927a

Browse files
authored
fix: Empty string is not consistent #311 (#312)
1 parent 82e0e29 commit c6a927a

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

type_carbon.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func (c Carbon) MarshalJSON() ([]byte, error) {
5555
func (c *Carbon) UnmarshalJSON(src []byte) error {
5656
v := string(bytes.Trim(src, `"`))
5757
if v == "" || v == "null" {
58+
c.isEmpty = true
5859
return nil
5960
}
6061
*c = *ParseByLayout(v, DefaultLayout)

type_unit_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ func (s *CarbonTypeSuite) TestCarbonType_UnmarshalJSON() {
149149

150150
s.Empty(model.Carbon1.String())
151151
s.Empty(model.Carbon2.String())
152+
s.False(model.Carbon1.IsValid())
153+
s.False(model.Carbon2.IsValid())
152154
})
153155

154156
s.Run("null value", func() {

0 commit comments

Comments
 (0)