Skip to content

Commit

Permalink
BUG: TypeError in xmp._converter_date (#813)
Browse files Browse the repository at this point in the history
Fix: Convert decimal to int before passing it to datetime

Closes #774
  • Loading branch information
MartinThoma committed Apr 24, 2022
1 parent 663ca98 commit 63b4c91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions PyPDF2/xmp.py
Expand Up @@ -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":
Expand Down
6 changes: 6 additions & 0 deletions Tests/test_xmp.py
Expand Up @@ -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

0 comments on commit 63b4c91

Please sign in to comment.