Skip to content

Conversation

@digizeph
Copy link
Member

@digizeph digizeph commented Jan 30, 2026

Summary

Add --time-format parameter to monocle parse and monocle search commands to control how timestamps are displayed in output.

Features

  • --time-format unix (default): Output timestamps as Unix epoch (integer or float)
    • Example: 1697043600 or 1697043600.5
  • --time-format rfc3339: Output timestamps in ISO 8601/RFC3339 format
    • Example: 2023-10-11T17:00:00+00:00

Usage Examples

Together with --format table and --fields timestamp,prefix,as_path, the updated command results can look much cleaner:

monocle search -t 2024-01-01 -d 1s -c route-views3 -p 140.99.244.0/23,201.87.136.0/24 --time-format rfc3339 --format table --fields timestamp,prefix,as_path`
╭─────────────────────────────────────┬─────────────────┬──────────────────────────────────────────────╮
│ timestamp                           │ prefix          │ as_path                                      │
├─────────────────────────────────────┼─────────────────┼──────────────────────────────────────────────┤
│ 2024-01-01T00:00:00.177294969+00:00 │ 140.99.244.0/23 │ 209 3356 3223 20068                          │
│ 2024-01-01T00:00:00.563082933+00:00 │ 140.99.244.0/23 │ 23367 1299 3356 3223 20068                   │
│ 2024-01-01T00:00:00.617777109+00:00 │ 201.87.136.0/24 │ 6939 52320 28598 265303 265303 265303 265303 │
╰─────────────────────────────────────┴─────────────────┴──────────────────────────────────────────────╯

Backward Compatibility

  • Default behavior unchanged: --time-format unix is the default, maintaining existing output format
  • JSON output unaffected: JSON output always uses numeric Unix timestamps regardless of --time-format setting, ensuring backward compatibility for scripts that parse JSON output
  • Non-breaking: All existing command invocations continue to work identically

Implementation Details

  • Added TimestampFormat enum to src/lens/utils.rs with variants Unix and Rfc3339
  • Updated elem_format.rs to support timestamp formatting via get_field_value_with_time_format()
  • Added --time-format CLI argument to both parse.rs and search.rs commands
  • JSON output functions (build_json_object) continue to use json!(elem.timestamp) to preserve numeric output

Add configurable timestamp output format for non-JSON output formats in
parse and search commands.

- Add TimestampFormat enum with 'unix' (default) and 'rfc3339' variants
- Unix format: Output timestamps as integer/float (e.g., 1697043600)
- RFC3339 format: Output timestamps in ISO 8601 format
  (e.g., 2023-10-11T17:00:00+00:00)
- JSON output always uses numeric timestamps for backward compatibility
- Affects table, psv, and markdown output formats
@digizeph digizeph linked an issue Jan 30, 2026 that may be closed by this pull request
@digizeph digizeph merged commit defef88 into main Jan 30, 2026
1 check passed
@digizeph digizeph deleted the timestring-output branch January 30, 2026 22:55
@digizeph digizeph mentioned this pull request Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

monocle search timestamp

1 participant