PHPOffice / PHPExcel

ARCHIVED
Other
11.46k stars 4.19k forks source link

OOCalc parsing date/time cells and timeZone bug #140

Open Strate opened 11 years ago

Strate commented 11 years ago

PHPExcel/Reader/OOCalc.php has this code:

$timezoneObj = new DateTimeZone('Europe/London');
$GMT = new DateTimeZone('UTC');
//......
$dateObj = new DateTime($cellDataOfficeAttributes['date-value'], $GMT);
$dateObj->setTimeZone($timezoneObj);

There is a bug, second setting of $timezoneObj is not needed, because DateTime object was created with UTC timeZone, but second timeZone is hardcoded for London.

Simply run this code to understand what I mean:

date_default_timezone_set('Europe/Moscow');
$timezoneObj = new DateTimeZone('Europe/London');
$GMT = new DateTimeZone('UTC');
$dateObj = new DateTime('2012-04-01 00:00:00', $GMT);
echo $dateObj->format( 'Y-m-d H:i:s' ); // prints expected `2012-04-01 00:00:00` string
$dateObj->setTimeZone($timezoneObj);
echo $dateObj->format( 'Y-m-d H:i:s' ); // prints unexpected `2012-04-01 01:00:00` string, 1 hour difference
kowach commented 8 years ago

I can confirm this bug, $timezoneObj is producing wrong date/time.