From d37e90250311426e74b0e5cecfd20f0b8fc00227 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sun, 24 Apr 2022 13:40:11 +0200 Subject: [PATCH] BUG: TypeError in xmp._converter_date Fix: Convert decimal to int before passing it to datetime Closes #774 --- PyPDF2/xmp.py | 4 ++++ Tests/test_xmp.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/PyPDF2/xmp.py b/PyPDF2/xmp.py index 85406d732..99f1c8667 100644 --- a/PyPDF2/xmp.py +++ b/PyPDF2/xmp.py @@ -107,6 +107,10 @@ def _converter_date(value): second = decimal.Decimal(m.group("second") or "0") seconds = second.to_integral(decimal.ROUND_FLOOR) milliseconds = (second - seconds) * 1000000 + + seconds = int(seconds) + milliseconds = int(milliseconds) + tzd = m.group("tzd") or "Z" dt = datetime.datetime(year, month, day, hour, minute, seconds, milliseconds) if tzd != "Z": diff --git a/Tests/test_xmp.py b/Tests/test_xmp.py index 941f9d30d..70bd359ca 100644 --- a/Tests/test_xmp.py +++ b/Tests/test_xmp.py @@ -42,3 +42,9 @@ def get_all_tiff(xmp): contents.append(content.data) data[tag.tagName] = contents return data + + +def test_regression_issue774(): + cls = PyPDF2.xmp.XmpInformation + date = cls._converter_date("2021-04-28T12:23:34.123Z") + assert date.year == 2021