question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect date when using .when with weekdays

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
timofurrercommented, Apr 15, 2018

Sounds even better! I’m looking forward to accept the change in the PR you’ve already made 😉

0reactions
timofurrercommented, Apr 17, 2018

Done in #147

Read more comments on GitHub >

github_iconTop Results From Across the Web

weekday function returns wrong date-what is DIRECT method ...
WEEKDAY(A1) returns the number 1 through 7, which TEXT would consider as the dates 1/1/1900 through 1/7/1900 in that context. The day of...
Read more >
Weekday function in is showing incorrect days - Stack Overflow
I have used the following code from the lubridate package. + 3 has been used to start at Tuesday as the 1st Jan...
Read more >
Incorrect Weekday based on Date - Tableau Community
In the Customers by Weekday view, it is recognizing each date 1 weekday later than it should be. Example: Monday, April 3rd, 2017...
Read more >
On what day of the week were you born? - Plus magazine!
Recently we learnt a very impressive trick: tell us the date you were born and we will almost immediately tell you what day...
Read more >
Docs - Moment.js
Week year, week, and weekday tokens. For these, the lowercase tokens use the locale aware week start days, and the uppercase tokens use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found