diff --git a/docs/advanced_usage.rst b/docs/advanced_usage.rst index 78e12736a..6a339b8e1 100644 --- a/docs/advanced_usage.rst +++ b/docs/advanced_usage.rst @@ -200,7 +200,7 @@ Troubleshooting: - Check your script's permission e.g. in case of permission error ``sudo chmod 755 post-consumption-example.sh`` - Pipe your scripts's output to a log file e.g. ``echo "${DOCUMENT_ID}" | tee --append /usr/src/paperless/scripts/post-consumption-example.log`` -.. _post-consumption-example.sh: https://github.com/jonaswinkler/paperless-ngx/blob/master/scripts/post-consumption-example.sh +.. _post-consumption-example.sh: https://github.com/paperless-ngx/paperless-ngx/blob/main/scripts/post-consumption-example.sh .. _advanced-file_name_handling: diff --git a/src/documents/parsers.py b/src/documents/parsers.py index cb70f4fc6..269fddbb4 100644 --- a/src/documents/parsers.py +++ b/src/documents/parsers.py @@ -23,6 +23,7 @@ from documents.signals import document_consumer_declaration # - XX. MONTH ZZZZ with XX being 1 or 2 and ZZZZ being 2 or 4 digits # - MONTH ZZZZ, with ZZZZ being 4 digits # - MONTH XX, ZZZZ with XX being 1 or 2 and ZZZZ being 4 digits +# - XX MON ZZZZ with XX being 1 or 2 and ZZZZ being 4 digits. MONTH is 3 letters # TODO: isnt there a date parsing library for this? @@ -31,7 +32,8 @@ DATE_REGEX = re.compile( r"(\b|(?!=([_-])))([0-9]{4}|[0-9]{2})[\.\/-]([0-9]{1,2})[\.\/-]([0-9]{1,2})(\b|(?=([_-])))|" # noqa: E501 r"(\b|(?!=([_-])))([0-9]{1,2}[\. ]+[^ ]{3,9} ([0-9]{4}|[0-9]{2}))(\b|(?=([_-])))|" # noqa: E501 r"(\b|(?!=([_-])))([^\W\d_]{3,9} [0-9]{1,2}, ([0-9]{4}))(\b|(?=([_-])))|" - r"(\b|(?!=([_-])))([^\W\d_]{3,9} [0-9]{4})(\b|(?=([_-])))", + r"(\b|(?!=([_-])))([^\W\d_]{3,9} [0-9]{4})(\b|(?=([_-])))|" + r"(\b|(?!=([_-])))(\b[0-9]{1,2}[ \.\/-][A-Z]{3}[ \.\/-][0-9]{4})(\b|(?=([_-])))", # noqa: E501 ) diff --git a/src/documents/tests/test_date_parsing.py b/src/documents/tests/test_date_parsing.py index f5987633f..06ad9876c 100644 --- a/src/documents/tests/test_date_parsing.py +++ b/src/documents/tests/test_date_parsing.py @@ -100,6 +100,57 @@ class TestDate(TestCase): datetime.datetime(2020, 3, 1, 0, 0, tzinfo=tz.gettz(settings.TIME_ZONE)), ) + def test_date_format_10(self): + text = "Customer Number Currency 22-MAR-2022 Credit Card 1934829304" + self.assertEqual( + parse_date("", text), + datetime.datetime(2022, 3, 22, 0, 0, tzinfo=tz.gettz(settings.TIME_ZONE)), + ) + + def test_date_format_11(self): + text = "Customer Number Currency 22 MAR 2022 Credit Card 1934829304" + self.assertEqual( + parse_date("", text), + datetime.datetime(2022, 3, 22, 0, 0, tzinfo=tz.gettz(settings.TIME_ZONE)), + ) + + def test_date_format_12(self): + text = "Customer Number Currency 22/MAR/2022 Credit Card 1934829304" + self.assertEqual( + parse_date("", text), + datetime.datetime(2022, 3, 22, 0, 0, tzinfo=tz.gettz(settings.TIME_ZONE)), + ) + + def test_date_format_13(self): + text = "Customer Number Currency 22.MAR.2022 Credit Card 1934829304" + self.assertEqual( + parse_date("", text), + datetime.datetime(2022, 3, 22, 0, 0, tzinfo=tz.gettz(settings.TIME_ZONE)), + ) + + def test_date_format_14(self): + text = "Customer Number Currency 22.MAR 2022 Credit Card 1934829304" + self.assertEqual( + parse_date("", text), + datetime.datetime(2022, 3, 22, 0, 0, tzinfo=tz.gettz(settings.TIME_ZONE)), + ) + + def test_date_format_15(self): + text = "Customer Number Currency 22.MAR.22 Credit Card 1934829304" + self.assertIsNone(parse_date("", text), None) + + def test_date_format_16(self): + text = "Customer Number Currency 22.MAR,22 Credit Card 1934829304" + self.assertIsNone(parse_date("", text), None) + + def test_date_format_17(self): + text = "Customer Number Currency 22,MAR,2022 Credit Card 1934829304" + self.assertIsNone(parse_date("", text), None) + + def test_date_format_18(self): + text = "Customer Number Currency 22 MAR,2022 Credit Card 1934829304" + self.assertIsNone(parse_date("", text), None) + def test_crazy_date_past(self, *args): self.assertIsNone(parse_date("", "01-07-0590 00:00:00"))