scrapinghub / scrapinghub/dateparser

Dateparser does not currently recognized time before date format

Open
#903 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Dateparser currently does not recognize 'times' before 'dates' formats. When parsing through a document sometimes 'times' are before 'dates'. It currently brings back a null value if 'times' are before 'dates'. I suggest incorporating something like the following code to find dates and move them to be in front of times. Something like the example below will help to keep your dateparser format working if times are before dates.

import re
import logging
import dateparser
from dateparser import parse

def dateparser(dt_input): 
        try:
            # Move 'Dates' to be in front of 'Times'
            date = re.search(r'(\d+(/|-|\.){1}\d+(/|-|\.){1}\d{1,4})', dt_input)
            dt_input = re.sub(date[1], '', dt_input).rstrip()
            dt_input = str(date[1] +' '+ dt_input)
            dt_input_parsed = parse(str(dt_input))
            return dt_input_parsed
        except Exception as e:
                logging.warning(f"Error in finding time in {dt_input}: {e}")

example:

dateparser("10:56:58 PM UTC+2:00 2/22/2018")
datetime.datetime(2019, 2, 22, 22, 56, 58, tzinfo=<StaticTzInfo 'UTC+02:00'>)

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 issue with dateparser.parse using the reported input, 10:56:58 PM UTC+2:00 2/22/2018, and inspect the parsing entry point. The fix should recognize times appearing before dates and return a parsed datetime with the supplied timezone, while preserving existing dateparser behavior.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.