[reportlab-users] Bug in invariant?

Roberto Alsina ralsina at netmanagers.com.ar
Sat Oct 31 16:02:18 EDT 2009


Hello, when trying to generate PDFs with invariant=1 in local_rl_config.py so
that tests don't fail because of timestamps in rst2pdf we found that files
still were different when generated by two persons.

And the difference was this:

$ ls -l 65*
-rw-r--r-- 1 ralsina users 16703 2009-10-31 16:34 65_patrick.pdf
-rw-r--r-- 1 ralsina users 16703 2009-10-31 16:35 65_roberto.pdf

The only difference between them is...

/CreationDate (D:20000101000000+06'00')

/CreationDate (D:20000101000000+03'00')

As you can see, the date is being fixed, but the timezone is not. I suspect
when the support for gmt offset was added, this slipped.

The fix is to change PDFDate like this (or something similar):

class PDFDate:
__PDFObject__ = True
# gmt offset now suppported
def __init__(self, invariant=rl_config.invariant, dateFormatter=None):
if invariant:
now = (2000,01,01,00,00,00,0)
self.dhh = 0; self.dmm = 0
else:
import time
now = tuple(time.localtime(_getTimeStamp())[:6])
from time import timezone
self.dhh, self.dmm = timezone // 3600, (timezone % 3600) % 60
self.date = now[:6]
self.dateFormatter = dateFormatter

def format(self, doc):
dfmt = self.dateFormatter or (
lambda yyyy,mm,dd,hh,m,s:
"D:%04d%02d%02d%02d%02d%02d%+03d'%02d'" %
(yyyy,mm,dd,hh,m,s,self.dhh,self.dmm))
return format(PDFString(dfmt(*self.date)), doc)


--
("\''/").__..-''"`-. . Roberto Alsina
`9_ 9 ) `-. ( ).`-._.`) KDE Developer (MFCH)
(_Y_.)' ._ ) `._`. " -.-' http://lateral.netmanagers.com.ar
_..`-'_..-_/ /-'_.' The 6,855th most popular site of Slovenia
(l)-'' ((i).' ((!.' according to alexa.com (27/5/2007)


More information about the reportlab-users mailing list