sisyphsu / dateparser

dateparser is a smart and high-performance date parser library, it supports hundreds of different formats, nearly all format that we may used. And this is also a showcase for "retree" algorithm.
MIT License
95 stars 23 forks source link

Custom Rule Failure #12

Closed jbaker-dstl closed 3 years ago

jbaker-dstl commented 3 years ago

I have the following code, which I would expect to be able to extract dates like 28X01X2020 (ddXmmXyyyy):

DateParser parser = DateParser.newBuilder()
    .addRule("(?<day>[0-9]{2})X(?<month>[0-9]{2})X(?<year>[0-9]{4})")
    .build();

System.out.println(parser.parseDate("28X01X2020"));

However, on running this, I get the following error:

java.time.format.DateTimeParseException: Text 28X01X2020 cannot parse at 0

I can't see how this differs significantly from the example in the README. Am I doing something wrong, or is this a bug?

sisyphsu commented 3 years ago

It's because dateparser only use lowercase rule pattern and input argument string.

You could use this rule by now: (?<day>[0-9]{2})x(?<month>[0-9]{2})x(?<year>[0-9]{4}).

And yes, this auto-lowercase feature looks like a bug, should find a way to make it more smart...