Skip to content
Open
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 ttlv/encoding_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func (j *jsonReader) DateTime(tag int) (time.Time, error) {
switch val := j.getValue().(type) {
case string:
if strings.HasPrefix(val, "0x") {
parsed, err := strconv.ParseUint(val[2:], 10, 64)
parsed, err := strconv.ParseUint(val[2:], 16, 64)
if err != nil {
return time.Time{}, err
}
Comment thread
phsym marked this conversation as resolved.
Expand Down
9 changes: 9 additions & 0 deletions ttlv/encoding_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ func (s *JsonDecodingSuite) TestDecodeDateTime() {
s.EqualValues(time.Date(2008, time.March, 14, 11, 56, 40, 0, time.UTC), n.UTC())
}

func (s *JsonDecodingSuite) TestDecodeDateTimeHex() {
// 0x47DA67F8 == 1205495800 == 2008-03-14T11:56:40Z
data := `{"tag": "0x420020", "type": "DateTime", "value": "0x47DA67F8"}`
r := s.newReader(data)
n, err := r.DateTime(0x420020)
s.NoError(err)
s.EqualValues(time.Date(2008, time.March, 14, 11, 56, 40, 0, time.UTC), n.UTC())
}

func (s *JsonDecodingSuite) TestDecodeInterval() {
data := `{"tag": "0x420020", "type": "Interval", "value": 864000}`
r := s.newReader(data)
Expand Down
Loading