Visitar URL original
BUG: TypeError in xmp._converter_date (#813) · py-pdf/pypdf@63b4c91 · GitHub
Skip to content

Commit 63b4c91

Browse files
authored
BUG: TypeError in xmp._converter_date (#813)
Fix: Convert decimal to int before passing it to datetime Closes #774
1 parent 663ca98 commit 63b4c91

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎PyPDF2/xmp.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def _converter_date(value):
107107
second = decimal.Decimal(m.group("second") or "0")
108108
seconds = second.to_integral(decimal.ROUND_FLOOR)
109109
milliseconds = (second - seconds) * 1000000
110+
111+
seconds = int(seconds)
112+
milliseconds = int(milliseconds)
113+
110114
tzd = m.group("tzd") or "Z"
111115
dt = datetime.datetime(year, month, day, hour, minute, seconds, milliseconds)
112116
if tzd != "Z":

‎Tests/test_xmp.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ def get_all_tiff(xmp):
4242
contents.append(content.data)
4343
data[tag.tagName] = contents
4444
return data
45+
46+
47+
def test_regression_issue774():
48+
cls = PyPDF2.xmp.XmpInformation
49+
date = cls._converter_date("2021-04-28T12:23:34.123Z")
50+
assert date.year == 2021

0 commit comments

Comments
 (0)