This repository has been archived by the owner on Feb 19, 2021. It is now read-only.
ENH: Enable parsing of date from filename (without strict filename structure) #440
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.
This PR adds a new (optional) feature that will pull a date out of the filename. I have a document source that is often just
YYYY-MM-DD
followed by some text description, and so none of the strict date parsing from https://github.com/danielquinn/paperless/blob/5c3cb1e4ab2bb286659339c721323406c5f7cc04/src/documents/models.py#L431-L435 was working for me. We already have a great date parser for the text of a file, so this extends it to the filename as well, providedPAPERLESS_FILENAME_DATE_ORDER
is defined in the config file.I also modified the massive date regex to permit year-first dates, as well as match on dates that are followed/preceded by either
-
or_
(rather than just word breaks).Against @danielquinn's wishes, I run with a time zone specified in my settings, and so I've changed the date tests to be specific to a user's defined time zone, as well as made the date formats explicit in each test, so there shouldn't be problems testing my code from Europe, or running the original tests in the US. I also added a blurb to the documentation, as well as a couple tests for the filename date parsing, and ensured that all the tests passed on my local machine after these additions.
Please feel free to add comments/suggestions/etc.