-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add decode nil to time.Time support.
- Loading branch information
Showing
2 changed files
with
16 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
| | | ||
| io/time_decoder.go | | ||
| | | ||
| LastModified: Feb 20, 2022 | | ||
| LastModified: May 27, 2022 | | ||
| Author: Ma Bingyao <[email protected]> | | ||
| | | ||
\*________________________________________________________*/ | ||
|
@@ -159,7 +159,7 @@ func (dec *Decoder) decodeTime(t reflect.Type, tag byte, p *time.Time) { | |
return | ||
} | ||
switch tag { | ||
case TagEmpty, TagFalse: | ||
case TagNull, TagEmpty, TagFalse: | ||
*p = time.Unix(0, 0) | ||
case TagTrue: | ||
*p = time.Unix(0, 1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
| | | ||
| io/time_decoder_test.go | | ||
| | | ||
| LastModified: Jun 05, 2021 | | ||
| LastModified: May 27, 2022 | | ||
| Author: Ma Bingyao <[email protected]> | | ||
| | | ||
\*________________________________________________________*/ | ||
|
@@ -34,12 +34,16 @@ func TestDecodeTime(t *testing.T) { | |
assert.NoError(t, enc.Encode(t1)) | ||
assert.NoError(t, enc.Encode(&t1)) | ||
assert.NoError(t, enc.Encode(t1)) | ||
assert.NoError(t, enc.Encode(nil)) | ||
assert.NoError(t, enc.Encode(nil)) | ||
|
||
t2 := Time(t1) | ||
assert.NoError(t, enc.Encode(&t2)) | ||
assert.NoError(t, enc.Encode(t2)) | ||
assert.NoError(t, enc.Encode(&t2)) | ||
assert.NoError(t, enc.Encode(t2)) | ||
assert.NoError(t, enc.Encode(nil)) | ||
assert.NoError(t, enc.Encode(nil)) | ||
|
||
dec := NewDecoder(([]byte)(sb.String())).Simple(false) | ||
var t3 *time.Time | ||
|
@@ -54,6 +58,11 @@ func TestDecodeTime(t *testing.T) { | |
assert.Equal(t, *t3, t1) | ||
dec.Decode(&t4) | ||
assert.Equal(t, t4, t1) | ||
dec.Decode(&t3) | ||
assert.Nil(t, t3) | ||
dec.Decode(&t4) | ||
assert.Equal(t, t4, time.Unix(0, 0)) | ||
|
||
dec.Decode(&t5) | ||
assert.Equal(t, *t5, t2) | ||
dec.Decode(&t6) | ||
|
@@ -62,4 +71,8 @@ func TestDecodeTime(t *testing.T) { | |
assert.Equal(t, *t5, t2) | ||
dec.Decode(&t6) | ||
assert.Equal(t, t6, t2) | ||
dec.Decode(&t5) | ||
assert.Nil(t, t5) | ||
dec.Decode(&t6) | ||
assert.Equal(t, t6, Time(time.Unix(0, 0))) | ||
} |