mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-02 18:47:10 -05:00 
			
		
		
		
	Merge pull request #576 from fantasticle/dev
Update regex date match patterns
This commit is contained in:
		
						commit
						ea26e1c72f
					
				@ -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:
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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"))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user