PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 5:37 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sun Sep 20, 2015 8:08 am 
Offline

Joined: Sun Sep 20, 2015 7:27 am
Posts: 1
I found a couple bugs in the parsing of creation/modification timestamps in PDFsharp 1.32 (and presumably 1.50).

In PdfSharp.Pdf.IO\Parser.cs :: ParseDateTime:
1. The added/subtracted time zone offset (ts) needs to be assigned back into the variable "datetime".
2. The time zone offset is added when it should be subtracted and vice versa.

Here is some corrected code:
Code:
TimeSpan ts = new TimeSpan(hh, mm, 0);
if (o == '-')  // Changed '+' to '-'
  datetime = datetime.Add(ts);  // Added "datetime = "
else
  datetime = datetime.Subtract(ts);  // Added "datetime = "


Here are some further suggestions to improve the code:

A. In PdfSharp.Pdf\PdfDocumentInformation.cs :: CreationDate/ModificationDate :: get, the second parameter to Elements.GetDateTime should be DateTime.MinValue instead of DateTime.Now so a constant known value is returned when either timestamp cannot be parsed/read. (DateTime.Now constantly changes and therefore cannot be easily compared.)

B. In PdfSharp.Pdf.IO\Parser.cs :: ParseDateTime, there should be some kind of warning or error when the date doesn't start with "D:" because this violates the PDF standard and I have no idea if DateTime.Parse will return the correct UTC time. I'm pretty sure the current call to DateTime.Parse will vary based on the your computer's cultural settings, so its output isn't trustworthy. If there are some PDF writing libraries that use a "plain English format", their precise format should be parsed instead of lazily calling DateTime.Parse with no options.

Thanks for the great library!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 45 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group