diff --git a/src/paperless_tika/parsers.py b/src/paperless_tika/parsers.py index 0558727f5..b6a9dd621 100644 --- a/src/paperless_tika/parsers.py +++ b/src/paperless_tika/parsers.py @@ -3,6 +3,7 @@ from pathlib import Path import httpx from django.conf import settings +from django.utils import timezone from tika_client import TikaClient from documents.parsers import DocumentParser @@ -63,6 +64,9 @@ class TikaDocumentParser(DocumentParser): self.text = self.text.strip() self.date = parsed.created + if self.date is not None and timezone.is_naive(self.date): + self.date = timezone.make_aware(self.date) + self.archive_path = self.convert_to_pdf(document_path, file_name) def convert_to_pdf(self, document_path, file_name): diff --git a/src/paperless_tika/tests/test_tika_parser.py b/src/paperless_tika/tests/test_tika_parser.py index f8f835189..4f64afc04 100644 --- a/src/paperless_tika/tests/test_tika_parser.py +++ b/src/paperless_tika/tests/test_tika_parser.py @@ -3,6 +3,11 @@ import os from pathlib import Path from unittest import mock +try: + import zoneinfo +except ImportError: + from backports import zoneinfo + from django.test import TestCase from django.test import override_settings from httpx import Request @@ -21,6 +26,7 @@ class TestTikaParser(HttpxMockMixin, TestCase): def tearDown(self) -> None: self.parser.cleanup() + @override_settings(TIME_ZONE="America/Chicago") def test_parse(self): # Pretend parse response self.httpx_mock.add_response( @@ -46,7 +52,12 @@ class TestTikaParser(HttpxMockMixin, TestCase): self.assertEqual( self.parser.date, - datetime.datetime(2020, 11, 21), + datetime.datetime( + 2020, + 11, + 21, + tzinfo=zoneinfo.ZoneInfo("America/Chicago"), + ), ) def test_metadata(self):