spali / go-rscp

Go library to communicate with a E3DC system implementing the RSCP (Remote Storage Control Protocol)
https://github.com/spali/go-rscp
MIT License
27 stars 9 forks source link

potential Bug for time.Time to json marshall with negative year. #17

Closed spali closed 2 years ago

spali commented 2 years ago

it looks like under some conditions (till now not reproduced) time values with go representation time.Date(0, 0, 0, 0, 0, 0, 0, time.UTC) get's returned. regarding time package documentation, this results in Year -1 which is invalid for json decoding that has a year range from 0-9999.

json decoding for time.Time requires a min of:

time.Date(1, 0, 0, 0, 0, 0, 0, time.UTC) // json marshal result:  `"0000-11-30T00:00:00Z"`.

rscp responses can contain:

time.Time: time.Time: time.Date(0, 0, 0, 0, 0, 0, 0, time.UTC) // not valid in json !

experienced once by my self and reported once here: https://github.com/spali/go-rscp/discussions/16#discussioncomment-2699393

Current guess is after a firmware update or maybe reboot of E3DC that the EMS_MANUAL_CHARGE_LASTSTART returns a negative year.

So for json marshaling, we need to fix this responses to at least year = 1. We assume the json output is mostly used in third-party directly, we "fix" the time to.

time.Unix(0, 0).UTC() // json: "1970-01-01T00:00:00Z"

This should be better supported in third party than smaller dates and are commonly also seen as "zero" time.