Skip to content

parse Apache-style timestamps with a numeric timezone offset#19

Open
HrachShah wants to merge 1 commit into
mainfrom
fix/utils-parse-apache-tz-offset
Open

parse Apache-style timestamps with a numeric timezone offset#19
HrachShah wants to merge 1 commit into
mainfrom
fix/utils-parse-apache-tz-offset

Conversation

@HrachShah

@HrachShah HrachShah commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Adds a missing datetime format to the timestamp parser in
log_analyzer_cli/utils.py so that Apache combined log lines with
a numeric timezone offset ("01/Jan/2025:12:00:00 -0700") can be
parsed as timezone-aware datetimes instead of returning None.

Summary by Sourcery

Extend timestamp parsing to handle Apache-style log entries with numeric timezone offsets while preserving support for existing formats.

New Features:

  • Support parsing Apache-style timestamps that include a numeric timezone offset as timezone-aware datetimes.

Tests:

  • Add unit tests covering Apache timestamps with positive and negative timezone offsets and verifying existing offset-less parsing remains functional.

The Apache combined log format always emits timestamps in the form
'01/Jan/2025:12:00:00 -0700' (day/Mon/year:hour:minute:second signhhmm).
The formats list in _try_parse_datetime only had the offset-less
'%d/%b/%Y:%H:%M:%S' form, so any Apache log line whose timestamp included
the numeric offset returned None from _try_parse_datetime, which
cascaded to parse_timestamp returning None, which made the apache
parser's _parse_timestamp fall back to the same offset-less format
inside the parser and silently drop the timezone information. The
result is that --start-time / --end-time filtering on a log file using
the canonical Apache combined format with offsets either timed the
window wrongly (because the time zones disagreed silently) or
produced no entries at all (because the parser-level fallback used
ts_str.split()[0] which left the offset in the string and made the
follow-up strptime call fail with the colon in the offset).

Add a '%d/%b/%Y:%H:%M:%S %z' entry to the formats list so the
offset-aware Apache timestamp is parsed in one shot, and add
tests/test_utils.py with three pin cases (positive offset, negative
offset, offset-less still works) so the next refactor of the format
list doesn't drop the offset form.
@sourcery-ai

sourcery-ai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds support for Apache-style timestamps with numeric timezone offsets to the internal timestamp parser and introduces tests to cover both offset and non-offset variants.

Sequence diagram for updated _try_parse_datetime parsing Apache timestamps with timezone offset

sequenceDiagram
  participant Caller
  participant Utils as _try_parse_datetime
  Caller->>Utils: _try_parse_datetime("01/Jan/2025:12:00:00 -0700")
  activate Utils
  Utils->>Utils: datetime.strptime(ts_str, "%Y-%m-%dT%H:%M:%S")
  Utils-->>Utils: ValueError
  Utils->>Utils: datetime.strptime(ts_str, "%Y-%m-%dT%H:%M:%S%z")
  Utils-->>Utils: ValueError
  Utils->>Utils: datetime.strptime(ts_str, "%d/%b/%Y:%H:%M:%S")
  Utils-->>Utils: ValueError
  Utils->>Utils: datetime.strptime(ts_str, "%d/%b/%Y:%H:%M:%S %z")
  Utils-->>Caller: timezone-aware datetime
  deactivate Utils
Loading

File-Level Changes

Change Details Files
Extend the internal timestamp parser to handle Apache-style timestamps that include a numeric timezone offset.
  • Add a new datetime format string that matches Apache timestamps with a numeric timezone offset to the list of tried formats in the parser helper
  • Preserve existing naive Apache timestamp parsing by keeping the previous format entry unchanged
src/log_analyzer_cli/utils.py
Add unit tests to verify parsing of Apache timestamps with and without numeric timezone offsets.
  • Add a test ensuring timestamps with a +0000 offset are parsed as timezone-aware datetimes with zero offset
  • Add a test ensuring timestamps with a negative offset (e.g., -0700) are parsed with the correct UTC offset
  • Add a regression test ensuring that naive Apache timestamps without an offset continue to parse successfully
tests/test_utils.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@HrachShah, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 48 minutes and 11 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7f2fae30-9c28-485b-8548-00c89af9f9b8

📥 Commits

Reviewing files that changed from the base of the PR and between e93757f and 4d46f1d.

📒 Files selected for processing (2)
  • src/log_analyzer_cli/utils.py
  • tests/test_utils.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/utils-parse-apache-tz-offset

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant