Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct Some Problems Which Will Show Up for PHP8.1 #2191

Merged
merged 7 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4477,7 +4477,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $pCell = null)
}

// if the token is a binary operator, pop the top two values off the stack, do the operation, and push the result back on the stack
if (isset(self::$binaryOperators[$token])) {
if (!is_numeric($token) && isset(self::$binaryOperators[$token])) {
// We must have two operands, error if we don't
if (($operand2Data = $stack->pop()) === null) {
return $this->raiseFormulaError('Internal error - Operand value missing from stack');
Expand Down
22 changes: 6 additions & 16 deletions src/PhpSpreadsheet/Shared/OLE.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,32 +502,22 @@ public static function localDateToOLE($date)
}
$dateTime = Date::dateTimeFromTimestamp("$date");

// factor used for separating numbers into 4 bytes parts
$factor = 2 ** 32;

// days from 1-1-1601 until the beggining of UNIX era
$days = 134774;
// calculate seconds
$big_date = $days * 24 * 3600 + (float) $dateTime->format('U');
// multiply just to make MS happy
$big_date *= 10000000;

$high_part = floor($big_date / $factor);
// lower 4 bytes
$low_part = floor((($big_date / $factor) - $high_part) * $factor);

// Make HEX string
$res = '';

for ($i = 0; $i < 4; ++$i) {
$hex = $low_part % 0x100;
$res .= pack('c', $hex);
$low_part /= 0x100;
}
for ($i = 0; $i < 4; ++$i) {
$hex = $high_part % 0x100;
$res .= pack('c', $hex);
$high_part /= 0x100;
$factor = 2 ** 56;
while ($factor >= 1) {
$hex = (int) floor($big_date / $factor);
$res = pack('c', $hex) . $res;
$big_date = fmod($big_date, $factor);
$factor /= 256;
}

return $res;
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Writer/Xlsx/StringTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function createStringTable(Worksheet $pSheet, $pExistingTable = null)
!is_object($cellValue) &&
($cellValue !== null) &&
$cellValue !== '' &&
!isset($aFlippedStringTable[$cellValue]) &&
($cell->getDataType() == DataType::TYPE_STRING || $cell->getDataType() == DataType::TYPE_STRING2 || $cell->getDataType() == DataType::TYPE_NULL)
($cell->getDataType() == DataType::TYPE_STRING || $cell->getDataType() == DataType::TYPE_STRING2 || $cell->getDataType() == DataType::TYPE_NULL) &&
!isset($aFlippedStringTable[$cellValue])
) {
$aStringTable[] = $cellValue;
$aFlippedStringTable[$cellValue] = true;
Expand Down
3 changes: 3 additions & 0 deletions tests/PhpSpreadsheetTests/Document/EpochTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ class EpochTest extends AbstractFunctional
public function providerFormats(): array
{
return [
['Ods', '1921-03-17 11:30:00Z'],
['Ods', '2021-03-17 11:30:00Z'],
['Ods', '2041-03-17 11:30:00Z'],
['Xls', '1921-03-17 11:30:00Z'],
['Xls', '2021-03-17 11:30:00Z'],
['Xls', '2041-03-17 11:30:00Z'],
['Xlsx', '1921-03-17 11:30:00Z'],
['Xlsx', '2021-03-17 11:30:00Z'],
['Xlsx', '2041-03-17 11:30:00Z'],
];
Expand Down