Skip to content

Make date formatting more reliable#65

Merged
rgwood merged 6 commits intorgwood:masterfrom
skdishansachin:refactor/date-parsing
Jan 9, 2026
Merged

Make date formatting more reliable#65
rgwood merged 6 commits intorgwood:masterfrom
skdishansachin:refactor/date-parsing

Conversation

@skdishansachin
Copy link
Copy Markdown
Contributor

Description

This replaces the old length-based date detection with proper RFC3339 timestamp parsing. Journal timestamps are now parsed using chrono instead of relying on string length. No behavior change for non-timestamp lines.

Related Issue - #33

@skdishansachin
Copy link
Copy Markdown
Contributor Author

@rgwood Let me know if anything should be changed or improved. Thank you!

@rgwood
Copy link
Copy Markdown
Owner

rgwood commented Jan 6, 2026

Hi, thanks for the PR!

I don't think this addresses the core issue - which is that the time format in logs can vary across system. This will work on systems where the date is formatted in RFC3339, and not on others.

Might still be an improvement. I'm a little busy but will take a closer look when I can.

@skdishansachin
Copy link
Copy Markdown
Contributor Author

Thanks for reviewing the PR! In the code, we always pass --output=short-iso to journalctl, which produces consistent RFC3339/ISO 8601–style timestamps across systems:

command.arg("--output=short-iso");

Looking at the man page, --output=short-iso shows timestamps in the RFC 3339 profile of ISO 8601.

So, using NaiveDateTime::parse_from_str("%Y-%m-%d %H:%M:%S") maybe reliably parse these timestamps. I wanted to check if you’re okay with updating the PR this way, or if you’d prefer sticking to parse_from_rfc3339 for strict RFC compliance.

Take your time to review and let me know if you see any potential issues.

@rgwood
Copy link
Copy Markdown
Owner

rgwood commented Jan 9, 2026

Right, I should have put more context in my initial issue. For reasons I don't fully understand, --output=short-iso doesn't seem to always work consistently.

On my laptop (Ubuntu 24.04, systemv v255):

2025-04-26T06:04:45-07:00 laptop anacron[31244]: Anacron 2.3 started on 2025-04-26

On an older server (Debian 11, systemd v247):

2025-10-06T11:07:44-0700 server dhcpcd[662]: wlan0: carrier acquired

I think this PR is an improvement (thank you! will probably merge it tonight) but I don't yet understand why journalctl is inconsistent like this.

@rgwood
Copy link
Copy Markdown
Owner

rgwood commented Jan 9, 2026

Ah, I found the change: systemd/systemd#29134

@rgwood
Copy link
Copy Markdown
Owner

rgwood commented Jan 9, 2026

Pushed a commit to make this work correctly on older systemd. Thanks for the PR!

@rgwood rgwood merged commit 2907a04 into rgwood:master Jan 9, 2026
1 check passed
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.

2 participants