scrapinghub / scrapinghub/dateparser

DATE_ORDER not always honored.

Open
#804 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Bug
Dominant language
Python
Stars
2.9k
Forks
520
Avg merge
22h 56m
Merged PRs (30d)
6

Description

Thanks for an excellent library!

Version: 0.7.6

Steps to reproduce:

import dateparser as dp
p1=dp.DateDataParser(settings={'DATE_ORDER': 'MDY','PREFER_LANGUAGE_DATE_ORDER':False})
p2=dp.DateDataParser(settings={'DATE_ORDER': 'DMY','PREFER_LANGUAGE_DATE_ORDER':False})

#good behavior
p1.get_date_data('02-23-2004')
{'date_obj': datetime.datetime(2004, 2, 23, 0, 0),
 'period': 'day',
 'locale': 'en'}

p2.get_date_data('02-23-2004')
{'date_obj': None, 'period': 'day', 'locale': None}

#bad behavior
p1.get_date_data('02-23-04')
{'date_obj': datetime.datetime(2004, 2, 23, 0, 0),
 'period': 'day',
 'locale': 'en'}

p2.get_date_data('02-23-04')
{'date_obj': datetime.datetime(2023, 4, 2, 0, 0),
 'period': 'day',
 'locale': 'en'}

My understanding is that with settings={'DATE_ORDER': 'DMY','PREFER_LANGUAGE_DATE_ORDER':False}, the parser should return None if it cannot parse with the specified DATE_ORDER.

The reason I need the parser to honor the DATE_ORDER (or fail the parse otherwise) is I have documents where the parse format is unknown, but it is known that all the dates in that document have the same parse format. If the DATE_ORDER was honored, I could parse all the dates with different DATE_ORDERs, and pick the DATE_ORDER which is consistent with all the dates in the document.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two DateDataParser.get_date_data cases from the issue with DATE_ORDER set to MDY and DMY and PREFER_LANGUAGE_DATE_ORDER disabled. Trace the DATE_ORDER handling for two-digit years; done means DMY does not parse 02-23-04 while MDY still returns the shown date, with a regression test covering both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.