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

[BUG] Unable to parse date time using defined patterns in Date Processor #4815

Open
sb2k16 opened this issue Aug 8, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@sb2k16
Copy link
Contributor

sb2k16 commented Aug 8, 2024

Date Processor in Data Prepper is unable to parse the date time given the below patterns defined in the pipeline YAML configuration.

Consider, testMessage.log has a line {"message": "Jul 30, 2024 3:28:55 PM"}, data prepper is unable to inject the @timestamp in the output event after parsing the date time from message key.

It looks like if we remove the line to default parsing for hour parseDefaulting(ChronoField.HOUR_OF_DAY, 0) from here, it is matching the expected behavior.

version: "2"
test-pipeline:
  source:
    file:
      path: "./testMessage.log"
      format: "json"
      record_type: "event"
  processor:
    - date:
        match:
          - key: "message"
            patterns: ["MMM dd, yyyy HH:mm:ss a", 
            "MMM dd, yyyy H:mm:ss a", "MMM dd, yyyy hh:mm:ss a", "MMM dd, yyyy h:mm:ss a", "MMM d, yyyy h:mm:ss a" ]
        destination: "@timestamp"
        destination_timezone: "UTC"
        to_origination_metadata: true
  sink:
    - stdout:
@sb2k16 sb2k16 added bug Something isn't working untriaged labels Aug 8, 2024
@serbozanrevd
Copy link

I am crossing the same bug.
I am definitely not a Java fluent.

But based on my understanding of the javadoc, I am not in favour of removing the line to default parsing for hour parseDefaulting(ChronoField.HOUR_OF_DAY, 0) from here.

I think that the patch should more in the direction of:

checking if a is in the pattern like in this example

            if (pattern.contains("a")) {
              dateTimeFormatterBuilder.parseDefaulting(ChronoField.HOUR_OF_AMPM, 0);
            } else {
              dateTimeFormatterBuilder.parseDefaulting(ChronoField.HOUR_OF_DAY, 0);
            }

And for the pattern am/pm, the hour should not be the letter h, but the letter k (link).

@serbozanrevd
Copy link

In fact, there is a PR already opened #4564.

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

3 participants