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

handle the case where the input in not an int or a float #3838

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 12 additions & 11 deletions src/PhpSpreadsheet/Shared/Date.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in src/PhpSpreadsheet/Shared/Date.php

View workflow job for this annotation

GitHub Actions / php-cs-fixer

Found violation(s) of type: single_space_after_construct

Check warning on line 1 in src/PhpSpreadsheet/Shared/Date.php

View workflow job for this annotation

GitHub Actions / php-cs-fixer

Found violation(s) of type: braces

namespace PhpOffice\PhpSpreadsheet\Shared;

Expand Down Expand Up @@ -220,17 +220,18 @@
} else {
$baseDate = new DateTime('1899-12-30', $timeZone);
}

$days = floor($excelTimestamp);
$partDay = $excelTimestamp - $days;
$hms = 86400 * $partDay;
$microseconds = (int) round(fmod($hms, 1) * 1000000);
$hms = (int) floor($hms);
$hours = intdiv($hms, 3600);
$hms -= $hours * 3600;
$minutes = intdiv($hms, 60);
$seconds = $hms % 60;

//handle the case where the input in not an int or float
if(is_int($excelTimestamp) || is_float($excelTimestamp)){

Check failure on line 224 in src/PhpSpreadsheet/Shared/Date.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 space(s) after IF keyword; 0 found

Check failure on line 224 in src/PhpSpreadsheet/Shared/Date.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 space(s) after closing parenthesis; found 0

Check failure on line 224 in src/PhpSpreadsheet/Shared/Date.php

View workflow job for this annotation

GitHub Actions / phpstan

Result of || is always true.
$days = floor($excelTimestamp);
$partDay = $excelTimestamp - $days;
$hms = 86400 * $partDay;
$microseconds = (int) round(fmod($hms, 1) * 1000000);
$hms = (int) floor($hms);
$hours = intdiv($hms, 3600);
$hms -= $hours * 3600;
$minutes = intdiv($hms, 60);
$seconds = $hms % 60;
}else return null;

Check failure on line 234 in src/PhpSpreadsheet/Shared/Date.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 space after closing brace; 0 found

Check failure on line 234 in src/PhpSpreadsheet/Shared/Date.php

View workflow job for this annotation

GitHub Actions / phpcs

Inline control structures are not allowed

Check failure on line 234 in src/PhpSpreadsheet/Shared/Date.php

View workflow job for this annotation

GitHub Actions / phpstan

Method PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject() should return DateTime but returns null.
if ($days >= 0) {
$days = '+' . $days;
}
Expand Down
Loading