fix: honor --time-format rfc3339 for JSON output - #127
Conversation
Previously, --time-format rfc3339 was silently ignored when using --format json, json-line, or json-pretty — the timestamp field always remained a numeric Unix value. build_json_object() now accepts a TimestampFormat parameter and emits a formatted RFC 3339 string when Rfc3339 is selected, while Unix (default) preserves the numeric f64 output byte-for-byte via the existing native serialization fallback. Fixes #123
There was a problem hiding this comment.
Pull request overview
Fixes #123 by making JSON outputs (json, json-line, json-pretty) honor --time-format rfc3339, so the timestamp field can be emitted as an RFC3339 string instead of always being a Unix numeric value.
Changes:
- Threaded
time_formatthrough JSON formatting sotimestampbecomes number (unix) or string (rfc3339) consistently for parse/search. - Updated CLI help text and README to state
--time-formatapplies to JSON formats too. - Added unit tests around JSON timestamp formatting.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils.rs | Updates TimestampFormat docs to reflect behavior across JSON and non-JSON formats. |
| src/bin/commands/search.rs | Updates clap help text for --time-format to include JSON formats. |
| src/bin/commands/parse.rs | Updates clap help text for --time-format to include JSON formats. |
| src/bin/commands/elem_format.rs | Threads time_format into JSON object construction and adds JSON timestamp tests. |
| README.md | Updates documentation to reflect JSON now honors --time-format. |
| CHANGELOG.md | Adds an Unreleased bug fix entry describing the behavior change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
build_json_object now always uses native BgpElem serialization for the default-fields case, overriding only the timestamp key when rfc3339 is selected. Previously, rfc3339 + default fields took the field-by-field path, dropping fields like origin_asns/only_to_customer that exist in native serialization but not in DEFAULT_FIELDS_PARSE. Also fix test to assert origin_asns (not in DEFAULT_FIELDS_PARSE) instead of peer_ip (which is), and add test for rfc3339 shape preservation. Addresses PR review feedback.
|
Addressed both review comments in 992979b: Line 305 (native serialization shape): Line 546 (test assertion): Replaced the |
The crate denies clippy::unwrap_used but .unwrap() is idiomatic in test code where panicking is the correct behavior. Add #[allow] on the test module to satisfy clippy --tests while keeping tests readable. Addresses PR review feedback.
|
Addressed the Added Note: CI runs |
Fixes #123
--time-format rfc3339was being ignored forjson,json-line, andjson-prettyoutput — thetimestampfield always stayed a numeric Unix value even when you asked for RFC 3339.Root cause was in
build_json_object(), which had a hardcoded "JSON always uses Unix timestamp" comment and didn't thread thetime_formatparameter through. Now it does:--time-format unix(default) → numerictimestampfield, unchanged for backward compat--time-format rfc3339→ stringtimestampfield like"2024-08-23T14:15:00+00:00"Applies to
parseandsearchconsistently. Updated the clap help text and README which previously said "non-JSON output" — that's no longer accurate.Added tests covering both formats for json-line output.