Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for relative dates using dateparser #484

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MatthewWilkes
Copy link

Hello! I appreciate this is a long-standing community discussion, and this PR may not be super helpful, but I implemented it to scratch my own itch and thought I'd offer it up.

Following the discussion in #10 there was a proposal to move to using dateparser for formatting dates. This isn't a perfect library, it currently makes some silly mistakes like parsing "1.5 hours ago" as "5 hours ago" and can be somewhat slow for confusing formats, but for all other day-to-day requirements I personally have, it handles them well.

This changes the DateTime parameter value to fall back on dateparser for any dates previously not allowable. This means that all currently acceptable dates are parsed in the same way, but some previously invalid dates are now allowable.

There's also an issue at #475 for relative dates specifically, which is implemented by PR #481. That implements a subset of the parsing directly using arrow, which I understand may well be preferable. I'm under no illusions that 1 hour of hacking is anything special, but wanted to share rather than hide it away.

If a date is entered but it cannot be parsed by arrow, try parsing it with dateparser. This enables support for a great many (but sadly not all) relative date expressions.
@@ -2,4 +2,5 @@ arrow>=1.0.0
click>=8.0
click-didyoumean
colorama; sys_platform == "win32"
dateparser

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that arrow is already here, wouldn't hurt to rework this change with arrow.dehumanize(s).

Can't talk for the maintainers, but I'd say using existing dependencies rather than adding a new one would increase chance of this being pulled in.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also looks like it could replace my PR more cleanly, so if you were to ingest the tests that my PR supports and take it further to days/weeks etc, that'd be an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants