[reportlab-users] Bug in invariant?
    Robin Becker 
    robin at reportlab.com
       
    Mon Nov  2 05:47:18 EST 2009
    
    
  
Thanks for this report; certainly didn't know about the timezone issue. I'll try 
and get this into the repository today.
Roberto Alsina wrote:
> 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)
> 
> 
-- 
Robin Becker
    
    
More information about the reportlab-users
mailing list