From 9c3753ed2b5fb166759df510a108d1f3ab00f6dc Mon Sep 17 00:00:00 2001 From: Patrick McCarty Date: Sat, 10 Jun 2023 17:26:13 -0700 Subject: [PATCH] Convert manual creation/mod times to UTC as well In line with the previous commit for consistency, convert the date strings from --creationdate and --moddate to UTC as well if a timezone is specified. --- src/img2pdf.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/img2pdf.py b/src/img2pdf.py index 4a1cd37..0e5fbda 100755 --- a/src/img2pdf.py +++ b/src/img2pdf.py @@ -722,7 +722,8 @@ class pdfdoc(object): self.writer.docinfo = PdfDict(indirect=True) def datetime_to_pdfdate(dt): - return dt.strftime("%Y%m%d%H%M%S%z") + dt_utc = dt.astimezone(tz=timezone.utc) + return dt_utc.strftime("%Y%m%d%H%M%S%z") for k in ["Title", "Author", "Creator", "Producer", "Subject"]: v = locals()[k.lower()] @@ -732,7 +733,7 @@ class pdfdoc(object): v = PdfString.encode(v) self.writer.docinfo[getattr(PdfName, k)] = v - now = datetime.now(tz=timezone.utc) + now = datetime.now().astimezone() for k in ["CreationDate", "ModDate"]: v = locals()[k.lower()] if v is None and nodate: @@ -752,7 +753,8 @@ class pdfdoc(object): ) def datetime_to_xmpdate(dt): - return dt.strftime("%Y-%m-%dT%H:%M:%S%z") + dt_utc = dt.astimezone(tz=timezone.utc) + return dt_utc.strftime("%Y-%m-%dT%H:%M:%S%z") self.xmp = b"""