Add support for relative dates using dateparser #484
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ondateparser
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.