Skip to content

fix: honor --time-format rfc3339 for JSON output - #127

Merged
digizeph merged 3 commits into
mainfrom
fix/json-line-time-format-123
Jun 28, 2026
Merged

fix: honor --time-format rfc3339 for JSON output#127
digizeph merged 3 commits into
mainfrom
fix/json-line-time-format-123

Conversation

@digizeph

Copy link
Copy Markdown
Member

Fixes #123

--time-format rfc3339 was being ignored for json, json-line, and json-pretty output — the timestamp field 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 the time_format parameter through. Now it does:

  • --time-format unix (default) → numeric timestamp field, unchanged for backward compat
  • --time-format rfc3339 → string timestamp field like "2024-08-23T14:15:00+00:00"

Applies to parse and search consistently. 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.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_format through JSON formatting so timestamp becomes number (unix) or string (rfc3339) consistently for parse/search.
  • Updated CLI help text and README to state --time-format applies 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.

Comment thread src/bin/commands/elem_format.rs Outdated
Comment thread src/bin/commands/elem_format.rs
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.
@digizeph

Copy link
Copy Markdown
Member Author

Addressed both review comments in 992979b:

Line 305 (native serialization shape): 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 and only_to_customer that exist in native serialization but not in DEFAULT_FIELDS_PARSE.

Line 546 (test assertion): Replaced the peer_ip assertion with origin_asns — which is in native BgpElem serialization but NOT in DEFAULT_FIELDS_PARSE, so the test now actually verifies the fallback path. Also added a new test test_default_fields_rfc3339_preserves_shape_overrides_timestamp that checks both shape preservation and timestamp override.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Comment thread src/bin/commands/elem_format.rs
Comment thread src/bin/commands/elem_format.rs
Comment thread src/bin/commands/elem_format.rs
Comment thread src/bin/commands/elem_format.rs
Comment thread src/bin/commands/elem_format.rs
Comment thread src/bin/commands/elem_format.rs
Comment thread src/bin/commands/elem_format.rs
Comment thread src/bin/commands/elem_format.rs
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.
@digizeph

Copy link
Copy Markdown
Member Author

Addressed the clippy::unwrap_used comments in ef93b28.

Added #[allow(clippy::unwrap_used)] on the test module. The crate denies clippy::unwrap_used at the binary root, but .unwrap() is idiomatic in test code where panicking is the correct behavior on assertion failure. The #[allow] keeps tests readable while satisfying cargo clippy --tests. This is consistent with the existing codebase pattern (e.g. src/lens/rpki/mod.rs uses #[allow(clippy::expect_used)] in its test module).

Note: CI runs cargo clippy --all-features -- -D warnings (without --tests), so test code isn't linted in CI. The #[allow] ensures correctness when linting with --tests locally.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@digizeph
digizeph merged commit 112e4ae into main Jun 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants