Skip to content

Incorrect date when using .when with weekdays #146

@alxwrd

Description

@alxwrd

hello! 👋

There appears to be an issue with maya.when() when using weekday names.

>>> today = maya.now()
>>> print(today)
'Sun, 15 Apr 2018 16:58:03 GMT'

>>> tomorrow = maya.when("monday", prefer_past=False)
>>> print(tomorrow)
'Mon, 09 Apr 2018 00:00:00 GMT'

dateparser seems to handle this correctly, but only when the setting 'PREFER_DATES_FROM' is set to 'future'.

>>> dateparser.parse("monday")
datetime.datetime(2018, 4, 9, 0, 0)

>>> dateparser.parse("monday", settings={"PREFER_DATES_FROM": "future"})
datetime.datetime(2018, 4, 16, 0, 0)

>>> dateparser.parse("Apr 16")
datetime.datetime(2018, 4, 16, 0, 0)

>>> dateparser.parse("Apr 16", settings={"PREFER_DATES_FROM": "past"})
datetime.datetime(2017, 4, 16, 0, 0)

The default setting for dateparser appears to be "current_period" from dateparser/dateparser_data/settings.py.

As the only way to alter the 'PREFER_DATES_FROM' setting is change prefer_past, there is currently no way to get the future day in this instance.

I'll open a PR with a failing test.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions