Skip to content

Parser result wrong for weird input string #701

Closed

Description

@StefanS111

I'm currently trying to parse this string: '23.18.05'
My expectation would be that results are only valid for a setting like DATE_ORDER': 'YDM' and especially never try to parse the middle number as a year whatsoever.
It actually turns out, that you receive the following return-value with dateparser.parse: datetime.datetime(2018, 5, 23, 0, 0)
and this value with get_date_data:
{'date_obj': datetime.datetime(2018, 5, 23, 0, 0), 'period': 'day', 'locale': 'it'}

(I do not think that my locale setting changes the outcome here. If any more information is needed, comments would be much appreciated.)

I would actually expect to get "None" as a result with such a string when no settings are given, especially as there are no existing date formats, where the year is found in the middle. Maybe I'm actually using it wrong, but I think not.

Also as a little backstory (not really related to the issue) I am actually trying to parse a date off of receipts and this string was found as a possible date by my RegEx, as it was given as current time on the receipt. I could not find any documentation information about ignoring such types of strings yet, as the standard datetime-parser and dateutil-parser also do not throw any errors with such a string here.

Activity

  1. Gallaecio commented on Jun 3, 2020

    @Gallaecio
    Contributor

    Marking as a bug as I don’t see a way to prevent that number from being parsed as a date (which does not necessarily mean that there isn’t one).

    (venv) [adrian@afonsox dateparser]$ git log --pretty=reference -n 1          
    b5167e8 (Merge pull request #696 from scrapinghub/fix-docstrings, 2020-05-28)
    (venv) [adrian@afonsox dateparser]$ python
    Python 3.8.2 (default, Apr  8 2020, 14:31:25) 
    [GCC 9.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import dateparser
    >>> dateparser.parse('23.18.05')
    datetime.datetime(2018, 5, 23, 0, 0)
    >>> dateparser.parse('23.18.05', locales=['en'])
    datetime.datetime(2018, 5, 23, 0, 0)
    >>> dateparser.parse('23.18.05', settings={'DATE_ORDER': 'MDY'})
    datetime.datetime(2018, 5, 23, 0, 0)
    >>> dateparser.parse('23.18.05', settings={'DATE_ORDER': 'MDY', 'PREFER_LANGUAGE_DATE_ORDER': False})
    datetime.datetime(2018, 5, 23, 0, 0)
    
  2. Gallaecio commented on Jun 3, 2020

    @Gallaecio
    Contributor

    On an unrelated note, if it’s not a date, what does that number stand for in the source string?

  3. StefanS111 commented on Jun 3, 2020

    @StefanS111
    Author

    Thank you for the marking. It actually represents the weirdest time-string i've seen around ever yet, being spaced by dots. Don't really know who'd ever get the idea to space his timestamps with dots on receipts... 😆

  4. Gallaecio commented on Jun 14, 2020

    @Gallaecio
    Contributor

    Looks like REQUIRE_PARTS, introduced in 0.7.5, does not make a difference either:

    >>> dateparser.parse('23.18.05', settings={'DATE_ORDER': 'MDY', 'REQUIRE_PARTS': ['day', 'month', 'year']})
    datetime.datetime(2018, 5, 23, 0, 0)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions