scrapinghub / scrapinghub/dateparser

parse method returns incorrect result

Open
#1,156 0 comments 0 reactions 1 assignee View on GitHub

@gutsytechster is already working on this.

Since Mar 24, 2023.

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

Description

I have found that the following MWE also seems to produce the same bug, even if PREFER_DATES_FROM is not set:

from datetime import datetime
from dateparser import parse
DATEPARSER_SETTINGS = {
    'TIMEZONE': 'UTC',
    'TO_TIMEZONE': 'UTC',
    'RETURN_AS_TIMEZONE_AWARE': False,
    'RELATIVE_BASE': datetime(2019, 8, 18, 3, 55, 1, 0)
}

dt = parse("9:57 PM MDT", settings=DATEPARSER_SETTINGS)  # datetime(2019, 8, 19, 3, 57, 0)
expected = datetime(2019, 8, 18, 3, 57, 0)
assert dt == expected  # fail:  dt is a day later than expected

Note that RELATIVE_BASE is set to 9:55:01 PM MDT on 17 August, which is before the specified time of "9:57 PM MDT" in the parse input. The returned dt value is neither the nearest future or past instance of 9:57 PM MDT relative to the current time (RELATIVE_BASE).

Originally posted by @Laogeodritt in https://github.com/scrapinghub/dateparser/issues/403#issuecomment-524612341

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.