Skip to content

Commit

Permalink
Add default timezone
Browse files Browse the repository at this point in the history
According to https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf page 87 section '7.9.4 Dates', date/timestamps should be, by default, in UTC/GMT. If no timezone is specified to \DateTime::createFromFormat it defaults to the system date/time which could pose problematic.
  • Loading branch information
rbairwell authored Mar 21, 2019
1 parent ec72a99 commit b2534af
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Smalot/PdfParser/Element/ElementDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ public static function parse($content, Document $document = null, &$offset = 0)
}

$format = self::$formats[strlen($name)];
$date = \DateTime::createFromFormat($format, $name);
$date = \DateTime::createFromFormat($format, $name,new \DateTimeZone('UTC'));
} else {
// special cases
if (preg_match('/^\d{1,2}-\d{1,2}-\d{4},?\s+\d{2}:\d{2}:\d{2}[\+-]\d{4}$/', $name)) {
$name = str_replace(',', '', $name);
$format = 'n-j-Y H:i:sO';
$date = \DateTime::createFromFormat($format, $name);
$date = \DateTime::createFromFormat($format, $name,new \DateTimeZone('UTC'));
}
}

Expand Down

0 comments on commit b2534af

Please sign in to comment.