Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI passed %Z fails to parse #20

Closed
jtmoon79 opened this issue Aug 9, 2022 · 3 comments
Closed

CLI passed %Z fails to parse #20

jtmoon79 opened this issue Aug 9, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@jtmoon79
Copy link
Owner

jtmoon79 commented Aug 9, 2022

Problem

The following command-line fails:

$ ./target/debug/s4 /var/log/syslog -a '2022-08-08 12:00:00 PST'
...
     process_dt: datetime_parse_from_str("2022-08-08 12:00:00 PST", "%Y-%m-%d %H:%M:%S %Z", true, +00:00)
        →datetime_parse_from_str: datetime_parse_from_str(pattern "%Y-%m-%d %H:%M:%S %Z", tz_offset +00:00, data "2022-08-08 12:00:00 PST")
        ←datetime_parse_from_str: DateTime::parse_from_str("2022-08-08 12:00:00 PST", "%Y-%m-%d %H:%M:%S %Z") failed ParseError: input is not enough for unique date and time
...
ERROR: Unable to parse a datetime from "2022-08-08 12:00:00 PST"

The --help message suggests possible datetimes:

$ ./target/release/s4 --help
super_speedy_syslog_searcher 0.0.25
....
DateTime Filter patterns may be:
    "%Y%m%dT%H%M%S"
    "%Y%m%dT%H%M%S%z"
    "%Y%m%dT%H%M%S%Z"
    "%Y-%m-%d %H:%M:%S"
    "%Y-%m-%d %H:%M:%S %z"
    "%Y-%m-%d %H:%M:%S %Z"
    "%Y-%m-%dT%H:%M:%S"
    "%Y-%m-%dT%H:%M:%S %z"
    "%Y-%m-%dT%H:%M:%S %Z"
    "%Y/%m/%d %H:%M:%S"
    "%Y/%m/%d %H:%M:%S %z"
    "%Y/%m/%d %H:%M:%S %Z"
    "%Y%m%d"
    "%Y%m%d %z"
    "%Y%m%d %Z"
    "+%s"
...

Solution

Support %Z parsing for command-line passed -a or -b.

@jtmoon79 jtmoon79 added the bug Something isn't working label Aug 9, 2022
@jtmoon79
Copy link
Owner Author

jtmoon79 commented Aug 9, 2022

One way to do this:
modify DTPD! defined in datetime.rs to have a flag, "is it acceptable for CLI?".
Gather those flagged DTPD! entries at run-time (or build-time), and iterate through them within fn process_dt, making calls to . This allows re-using the facilities built in datetime.rs, and not having divergent methods for transforming a string to a DateTimeL.

@jtmoon79
Copy link
Owner Author

jtmoon79 commented Aug 9, 2022

A different way to do this:

Modify fn datetime_parse_from_str in datetime.rs to do the timezone mapping from %Z value to %z value.

Or add a wrapper to datetime_parse_from_str that is only used by process_dt in bin.rs. The wrapper does the timezone value mapping.

jtmoon79 added a commit that referenced this issue Aug 13, 2022
Remove unnsupported %Z in --help message. Temporary cover-up of Issue #20.

Issue #20
@jtmoon79 jtmoon79 self-assigned this Sep 20, 2022
@jtmoon79
Copy link
Owner Author

Fixed by a71c5e8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant