utils: parse microsecond-precise ISO 8601 and Apache offsets, keep --start-time/--end-time comparable - #27
Conversation
…start-time/--end-time comparable
Reviewer's GuideEnhances timestamp parsing to support microsecond-precise ISO 8601 and Apache log offsets, and makes CLI time-bound filtering robust when comparing offset-aware log entries against naive start/end times, backed by targeted tests. Sequence diagram for CLI timestamp parsing and naive bounds comparisonsequenceDiagram
actor User
participant CLI as _parse_file
participant Utils as parse_timestamp
participant Dt as datetime
User->>CLI: _parse_file(file_path, start_time, end_time)
loop for each line
CLI->>Utils: parse_timestamp(line)
Utils-->>CLI: timestamp
alt start_time or end_time is set
alt timestamp.tzinfo is not None
CLI->>Dt: timestamp.replace(tzinfo=None)
Dt-->>CLI: compare_ts (naive)
else timestamp.tzinfo is None
CLI->>CLI: compare_ts = timestamp
end
alt compare_ts < start_time
CLI->>CLI: continue (skip line)
else compare_ts > end_time
CLI->>CLI: continue (skip line)
end
end
CLI->>CLI: parser.parse(line)
end
CLI-->>User: parsed results
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reached
Next review available in: 56 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
parse_timestampinlog_analyzer_cli/utils.pycould not parse several common timestamp shapes that the regex it tries already captures:2025-10-10T13:55:36.123456+00:00)2025-10-10T13:55:36.123456Z)2025-10-10 13:55:36.123456+00:00)It also lost the offset on Apache common log timestamps: the regex captured
10/Oct/2025:13:55:36only, dropping the trailing±HHMMentirely.Changes
src/log_analyzer_cli/utils.py:_try_parse_datetimenow orders formats from most specific to least specific, so aT%H:%M:%S.%f%zshape is tried before a plainT%H:%M:%S%z(and beforeT%H:%M:%S.%fwithout a timezone). Added the previously missingT%H:%M:%S.%f%z,H:%M:%S.%f%z,T%H:%M:%S %z, and Apache's%d/%b/%Y:%H:%M:%S %zformats.±HHMMoffset, and the new%d/%b/%Y:%H:%M:%S %zformat preserves it on the returneddatetime.src/log_analyzer_cli/cli.py:_parse_filenow strips a tz-awaretzinfofrom the parsed timestamp before comparing it against a naive--start-time/--end-timebound, so the bounds can filter a log whose entries carry a UTC offset without raisingTypeError: can't compare offset-naive and offset-aware datetimes.tests/test_utils.py: 26 new tests covering microsecond-precise ISO shapes (with and without timezone, with and withoutZ, with positive and negative offsets), the space-separator form, Apache common log with and without offset, RFC 3164 syslog, naive inputs, and a regression that asserts fractional seconds and the timezone offset round-trip.Test results
python3 -m pytest tests/→ 73 passed (47 pre-existing + 26 new).Summary by Sourcery
Extend timestamp parsing and comparison to handle timezone-aware and microsecond-precise log entries while keeping CLI time range filters robust.
New Features:
Enhancements:
Tests: