Invalid dates in PDF metadata

55 views
Skip to first unread message

uni...@gmail.com

unread,
May 15, 2017, 8:10:13 AM5/15/17
to reportl...@googlegroups.com
Hello, all.

When generating PDFs, creation and modification dates use incorrect
values. The cause seems to be the use of time.timezone in PDFDate class.

time.timezone is defined as offset from local timezone to UTC, not the
other way around.

This results in dates in GMT+3 timezone being written as
"D:20170515143223-03'00'".

This is wrong, according to PDF 1.7 spec, section 3.8.3.


--
WBR, Unik

navi

unread,
Feb 10, 2023, 7:45:35 AM2/10/23
to reportlab-users
This is really wrong in the PDF metadata. https://docs.python.org/3/library/time.html?highlight=time#time.timezone

And the fix is quite simple. In "reportlab.lib.utils::class TimeStamp", timezone is set as "dhh = int(time.timezone / (3600.0))". It should be "dhh = -int(time.timezone / (3600.0))".

Navi

Steve Randall

unread,
Oct 9, 2024, 5:59:40 PM10/9/24
to reportlab-users
Where there's one bug, there may be another. I identified 4 distinct errors in this code. Besides time.timezone having the opposite of the expected sign, it does not account for DST. Also, the "% 60" in the dmm calculation extracts the seconds, not the minutes. And if you fix that, the minutes will be wrong if there's ever a 45-minute timezone in the western hemisphere.

--- lib/utils.py.orig 2024-10-09 15:04:02.828125111 -0500
+++ lib/utils.py 2024-10-09 15:08:07.019573053 -0500
@@ -1261,10 +1261,10 @@
             self.tzname = 'UTC'
         else:
             t = time.time()
-            lt = tuple(time.localtime(t))
-            dhh = int(time.timezone / (3600.0))
-            dmm = (time.timezone % 3600) % 60
-            self.tzname = ''
+            lt = time.localtime(t)
+            dhh = int(lt.tm_gmtoff / 3600)
+            dmm = int(abs(lt.tm_gmtoff) % 3600 / 60)
+            self.tzname = lt.tm_zone
         self.t = t
         self.lt = lt
         self.YMDhms = tuple(lt)[:6]
Reply all
Reply to author
Forward
0 new messages