Open
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Changing
Full/Emptyfrom*time.Timetotime.Timeremoves the explicit nil/no-value state; double-check all callers and MQTT consumers correctly interpret the zerotime.Timeand that this doesn’t introduce ambiguity with legitimatetime.Time{}values. - The struct tags
json:"full,omitzero"/json:"empty,omitzero"are non-standard for Go’sencoding/json(which only understandsomitempty); confirm that your JSON marshaller actually supportsomitzeroor adjust the tags to match the serializer being used.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Changing `Full`/`Empty` from `*time.Time` to `time.Time` removes the explicit nil/no-value state; double-check all callers and MQTT consumers correctly interpret the zero `time.Time` and that this doesn’t introduce ambiguity with legitimate `time.Time{}` values.
- The struct tags `json:"full,omitzero"` / `json:"empty,omitzero"` are non-standard for Go’s `encoding/json` (which only understands `omitempty`); confirm that your JSON marshaller actually supports `omitzero` or adjust the tags to match the serializer being used.
## Individual Comments
### Comment 1
<location path="core/site_optimizer.go" line_range="73-74" />
<code_context>
batteryDetail
- Full *time.Time `json:"full"`
- Empty *time.Time `json:"empty"`
+ Full time.Time `json:"full,omitzero"`
+ Empty time.Time `json:"empty,omitzero"`
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `omitzero` in JSON tags is non-standard and likely ignored by `encoding/json`
`encoding/json` only supports the `omitempty` option. With `json:"full,omitzero"`, `Full` will still always be marshaled, and a zero `time.Time` becomes `"0001-01-01T00:00:00Z"`. If you need to omit zero timestamps, you’ll need a custom `MarshalJSON` (on `batteryResult` or a wrapper `time.Time` type) rather than relying on this tag option.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Comment on lines
+73
to
+74
| Full time.Time `json:"full,omitzero"` | ||
| Empty time.Time `json:"empty,omitzero"` |
Contributor
There was a problem hiding this comment.
issue (bug_risk): Using omitzero in JSON tags is non-standard and likely ignored by encoding/json
encoding/json only supports the omitempty option. With json:"full,omitzero", Full will still always be marshaled, and a zero time.Time becomes "0001-01-01T00:00:00Z". If you need to omit zero timestamps, you’ll need a custom MarshalJSON (on batteryResult or a wrapper time.Time type) rather than relying on this tag option.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #28811