From 9b34f8746bc931d0a2e6785625050841171a23a5 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Wed, 12 May 2021 17:03:06 +0200 Subject: [PATCH] Use correct Exception, ensure that Shared\Date is referenced by a synonym to ensure clarity, and ensure case-sensitivity for class references --- .../Calculation/DateTimeExcel/Constants.php | 1 + .../Calculation/DateTimeExcel/Date.php | 4 ++-- .../Calculation/DateTimeExcel/DateParts.php | 14 ++++++------ .../Calculation/DateTimeExcel/DateValue.php | 4 ++-- .../Calculation/DateTimeExcel/Days.php | 8 +++---- .../Calculation/DateTimeExcel/Days360.php | 6 ++--- .../Calculation/DateTimeExcel/Difference.php | 8 +++---- .../Calculation/DateTimeExcel/Helpers.php | 22 +++++++++---------- .../Calculation/DateTimeExcel/Month.php | 3 +-- .../Calculation/DateTimeExcel/NetworkDays.php | 3 +-- .../Calculation/DateTimeExcel/Time.php | 10 ++++----- .../Calculation/DateTimeExcel/TimeParts.php | 8 +++---- .../Calculation/DateTimeExcel/TimeValue.php | 6 ++--- .../Calculation/DateTimeExcel/Week.php | 16 +++++++------- .../Calculation/DateTimeExcel/WorkDay.php | 3 +-- .../Calculation/DateTimeExcel/YearFrac.php | 6 ++--- 16 files changed, 60 insertions(+), 62 deletions(-) diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Constants.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Constants.php index da1b81c10b..1165eb1fee 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Constants.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Constants.php @@ -22,6 +22,7 @@ class Constants const DOW_FRIDAY = 6; const DOW_SATURDAY = 7; const STARTWEEK_MONDAY_ISO = 21; + const METHODARR = [ self::STARTWEEK_SUNDAY => self::DOW_SUNDAY, self::DOW_MONDAY, diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php index 3ec6cfbbcc..d18e2371c3 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; @@ -102,7 +102,7 @@ private static function getYear($year, int $baseYear): int $year += 1900; } - return $year; + return (int) $year; } /** diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateParts.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateParts.php index f1ada4357b..37ea031515 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateParts.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateParts.php @@ -4,7 +4,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class DateParts { @@ -36,7 +36,7 @@ public static function day($dateValue) } // Execute function - $PHPDateObject = Date::excelToDateTimeObject($dateValue); + $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue); return (int) $PHPDateObject->format('j'); } @@ -62,12 +62,12 @@ public static function month($dateValue) } catch (Exception $e) { return $e->getMessage(); } - if ($dateValue < 1 && Date::getExcelCalendar() === DATE::CALENDAR_WINDOWS_1900) { + if ($dateValue < 1 && SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_WINDOWS_1900) { return 1; } // Execute function - $PHPDateObject = Date::excelToDateTimeObject($dateValue); + $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue); return (int) $PHPDateObject->format('n'); } @@ -94,11 +94,11 @@ public static function year($dateValue) return $e->getMessage(); } - if ($dateValue < 1 && Date::getExcelCalendar() === DATE::CALENDAR_WINDOWS_1900) { + if ($dateValue < 1 && SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_WINDOWS_1900) { return 1900; } // Execute function - $PHPDateObject = Date::excelToDateTimeObject($dateValue); + $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue); return (int) $PHPDateObject->format('Y'); } @@ -110,7 +110,7 @@ public static function year($dateValue) private static function weirdCondition($dateValue): int { // Excel does not treat 0 consistently for DAY vs. (MONTH or YEAR) - if (Date::getExcelCalendar() === DATE::CALENDAR_WINDOWS_1900 && Functions::getCompatibilityMode() == Functions::COMPATIBILITY_EXCEL) { + if (SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_WINDOWS_1900 && Functions::getCompatibilityMode() == Functions::COMPATIBILITY_EXCEL) { if (is_bool($dateValue)) { return (int) $dateValue; } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php index 4c7544562c..de767fca6c 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php @@ -4,7 +4,7 @@ use DateTimeImmutable; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class DateValue { @@ -36,7 +36,7 @@ class DateValue public static function fromString($dateValue) { $dti = new DateTimeImmutable(); - $baseYear = Date::getExcelCalendar(); + $baseYear = SharedDateHelper::getExcelCalendar(); $dateValue = trim(Functions::flattenSingleValue($dateValue), '"'); // Strip any ordinals because they're allowed in Excel (English only) $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue) ?? ''; diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php index 73465ccf34..5a97d8df8a 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php @@ -3,9 +3,9 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; use DateTimeInterface; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class Days { @@ -34,8 +34,8 @@ public static function between($endDate, $startDate) } // Execute function - $PHPStartDateObject = Date::excelToDateTimeObject($startDate); - $PHPEndDateObject = Date::excelToDateTimeObject($endDate); + $PHPStartDateObject = SharedDateHelper::excelToDateTimeObject($startDate); + $PHPEndDateObject = SharedDateHelper::excelToDateTimeObject($endDate); $days = Functions::VALUE(); $diff = $PHPStartDateObject->diff($PHPEndDateObject); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php index d11cdd1627..bbc5d16aaa 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php @@ -4,7 +4,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class Days360 { @@ -50,12 +50,12 @@ public static function between($startDate = 0, $endDate = 0, $method = false) } // Execute function - $PHPStartDateObject = Date::excelToDateTimeObject($startDate); + $PHPStartDateObject = SharedDateHelper::excelToDateTimeObject($startDate); $startDay = $PHPStartDateObject->format('j'); $startMonth = $PHPStartDateObject->format('n'); $startYear = $PHPStartDateObject->format('Y'); - $PHPEndDateObject = Date::excelToDateTimeObject($endDate); + $PHPEndDateObject = SharedDateHelper::excelToDateTimeObject($endDate); $endDay = $PHPEndDateObject->format('j'); $endMonth = $PHPEndDateObject->format('n'); $endYear = $PHPEndDateObject->format('Y'); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php index 4e061d7dcd..6adeca179a 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php @@ -4,9 +4,9 @@ use DateInterval; use DateTime; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class Difference { @@ -33,12 +33,12 @@ public static function interval($startDate, $endDate, $unit = 'D') } // Execute function - $PHPStartDateObject = Date::excelToDateTimeObject($startDate); + $PHPStartDateObject = SharedDateHelper::excelToDateTimeObject($startDate); $startDays = (int) $PHPStartDateObject->format('j'); $startMonths = (int) $PHPStartDateObject->format('n'); $startYears = (int) $PHPStartDateObject->format('Y'); - $PHPEndDateObject = Date::excelToDateTimeObject($endDate); + $PHPEndDateObject = SharedDateHelper::excelToDateTimeObject($endDate); $endDays = (int) $PHPEndDateObject->format('j'); $endMonths = (int) $PHPEndDateObject->format('n'); $endYears = (int) $PHPEndDateObject->format('Y'); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php index 2d1b6af176..9503401c0d 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php @@ -5,7 +5,7 @@ use DateTime; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class Helpers { @@ -31,7 +31,7 @@ public static function isLeapYear($year): bool public static function getDateValue($dateValue, bool $allowBool = true): float { if (is_object($dateValue)) { - $retval = Date::PHPToExcel($dateValue); + $retval = SharedDateHelper::PHPToExcel($dateValue); if (is_bool($retval)) { throw new Exception(Functions::VALUE()); } @@ -81,7 +81,7 @@ public static function getTimeValue($timeValue) public static function adjustDateByMonths($dateValue = 0, float $adjustmentMonths = 0): DateTime { // Execute function - $PHPDateObject = Date::excelToDateTimeObject($dateValue); + $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue); $oMonth = (int) $PHPDateObject->format('m'); $oYear = (int) $PHPDateObject->format('Y'); @@ -149,7 +149,7 @@ public static function returnIn3FormatsArray(array $dateArray, bool $noFrac = fa ); } $excelDateValue = - Date::formattedPHPToExcel( + SharedDateHelper::formattedPHPToExcel( $dateArray['year'], $dateArray['month'], $dateArray['day'], @@ -162,7 +162,7 @@ public static function returnIn3FormatsArray(array $dateArray, bool $noFrac = fa } // RETURNDATE_UNIX_TIMESTAMP) - return (int) Date::excelToTimestamp($excelDateValue); + return (int) SharedDateHelper::excelToTimestamp($excelDateValue); } /** @@ -177,11 +177,11 @@ public static function returnIn3FormatsFloat(float $excelDateValue) return $excelDateValue; } if ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) { - return (int) Date::excelToTimestamp($excelDateValue); + return (int) SharedDateHelper::excelToTimestamp($excelDateValue); } // RETURNDATE_PHP_DATETIME_OBJECT - return Date::excelToDateTimeObject($excelDateValue); + return SharedDateHelper::excelToDateTimeObject($excelDateValue); } /** @@ -196,13 +196,13 @@ public static function returnIn3FormatsObject(DateTime $PHPDateObject) return $PHPDateObject; } if ($retType === Functions::RETURNDATE_EXCEL) { - return (float) Date::PHPToExcel($PHPDateObject); + return (float) SharedDateHelper::PHPToExcel($PHPDateObject); } // RETURNDATE_UNIX_TIMESTAMP - $stamp = Date::PHPToExcel($PHPDateObject); + $stamp = SharedDateHelper::PHPToExcel($PHPDateObject); $stamp = is_bool($stamp) ? ((int) $stamp) : $stamp; - return (int) Date::excelToTimestamp($stamp); + return (int) SharedDateHelper::excelToTimestamp($stamp); } private static function baseDate(): int @@ -210,7 +210,7 @@ private static function baseDate(): int if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) { return 0; } - if (Date::getExcelCalendar() === Date::CALENDAR_MAC_1904) { + if (SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_MAC_1904) { return 0; } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php index 10cb27fdf7..560b7a8071 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php @@ -2,8 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; -use Exception; -use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; class Month { diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php index ded4f64761..d0f53cf392 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php @@ -2,9 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; class NetworkDays { diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php index c72bcf6047..fb5e49652f 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php @@ -5,7 +5,7 @@ use DateTime; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class Time { @@ -57,13 +57,13 @@ public static function fromHMS($hour, $minute, $second) // Execute function $retType = Functions::getReturnDateType(); if ($retType === Functions::RETURNDATE_EXCEL) { - $calendar = Date::getExcelCalendar(); - $date = (int) ($calendar !== Date::CALENDAR_WINDOWS_1900); + $calendar = SharedDateHelper::getExcelCalendar(); + $date = (int) ($calendar !== SharedDateHelper::CALENDAR_WINDOWS_1900); - return (float) Date::formattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second); + return (float) SharedDateHelper::formattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second); } if ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) { - return (int) Date::excelToTimestamp(Date::formattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600 + return (int) SharedDateHelper::excelToTimestamp(SharedDateHelper::formattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600 } // RETURNDATE_PHP_DATETIME_OBJECT // Hour has already been normalized (0-23) above diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php index 3e07da0864..49cd983d87 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php @@ -4,7 +4,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class TimeParts { @@ -37,7 +37,7 @@ public static function hour($timeValue) // Execute function $timeValue = fmod($timeValue, 1); - $timeValue = Date::excelToDateTimeObject($timeValue); + $timeValue = SharedDateHelper::excelToDateTimeObject($timeValue); return (int) $timeValue->format('H'); } @@ -71,7 +71,7 @@ public static function minute($timeValue) // Execute function $timeValue = fmod($timeValue, 1); - $timeValue = Date::excelToDateTimeObject($timeValue); + $timeValue = SharedDateHelper::excelToDateTimeObject($timeValue); return (int) $timeValue->format('i'); } @@ -105,7 +105,7 @@ public static function second($timeValue) // Execute function $timeValue = fmod($timeValue, 1); - $timeValue = Date::excelToDateTimeObject($timeValue); + $timeValue = SharedDateHelper::excelToDateTimeObject($timeValue); return (int) $timeValue->format('s'); } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php index 6760076136..73b7ba91fe 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php @@ -4,7 +4,7 @@ use Datetime; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class TimeValue { @@ -44,13 +44,13 @@ public static function fromString($timeValue) $retValue = Functions::VALUE(); if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) { // OpenOffice-specific code removed - it works just like Excel - $excelDateValue = Date::formattedPHPToExcel(1900, 1, 1, $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']) - 1; + $excelDateValue = SharedDateHelper::formattedPHPToExcel(1900, 1, 1, $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']) - 1; $retType = Functions::getReturnDateType(); if ($retType === Functions::RETURNDATE_EXCEL) { $retValue = (float) $excelDateValue; } elseif ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) { - $retValue = (int) $phpDateValue = Date::excelToTimestamp($excelDateValue + 25569) - 3600; + $retValue = (int) $phpDateValue = SharedDateHelper::excelToTimestamp($excelDateValue + 25569) - 3600; } else { $retValue = new DateTime('1900-01-01 ' . $PHPDateArray['hour'] . ':' . $PHPDateArray['minute'] . ':' . $PHPDateArray['second']); } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php index 928bfc1404..6636222104 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php @@ -5,7 +5,7 @@ use DateTime; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class Week { @@ -45,7 +45,7 @@ public static function number($dateValue, $method = Constants::STARTWEEK_SUNDAY) try { $method = self::validateMethod($method); if ($dateValue === null) { // boolean not allowed - $dateValue = (Date::getExcelCalendar() === DATE::CALENDAR_MAC_1904 || $method === Constants::DOW_SUNDAY) ? 0 : 1; + $dateValue = (SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_MAC_1904 || $method === Constants::DOW_SUNDAY) ? 0 : 1; } $dateValue = self::validateDateValue($dateValue); if (!$dateValue && self::buggyWeekNum1900($method)) { @@ -57,7 +57,7 @@ public static function number($dateValue, $method = Constants::STARTWEEK_SUNDAY) } // Execute function - $PHPDateObject = Date::excelToDateTimeObject($dateValue); + $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue); if ($method == Constants::STARTWEEK_MONDAY_ISO) { Helpers::silly1900($PHPDateObject); @@ -104,7 +104,7 @@ public static function isoWeekNumber($dateValue) } // Execute function - $PHPDateObject = Date::excelToDateTimeObject($dateValue); + $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue); Helpers::silly1900($PHPDateObject); return (int) $PHPDateObject->format('W'); @@ -138,7 +138,7 @@ public static function day($dateValue, $style = 1) } // Execute function - $PHPDateObject = Date::excelToDateTimeObject($dateValue); + $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue); Helpers::silly1900($PHPDateObject); $DoW = (int) $PHPDateObject->format('w'); @@ -189,7 +189,7 @@ private static function dow0Becomes7(int $DoW): int */ private static function apparentBug($dateValue): bool { - if (Date::getExcelCalendar() !== DATE::CALENDAR_MAC_1904) { + if (SharedDateHelper::getExcelCalendar() !== SharedDateHelper::CALENDAR_MAC_1904) { if (is_bool($dateValue)) { return true; } @@ -241,14 +241,14 @@ private static function validateMethod($method): int private static function buggyWeekNum1900(int $method): bool { - return $method === Constants::DOW_SUNDAY && Date::getExcelCalendar() === Date::CALENDAR_WINDOWS_1900; + return $method === Constants::DOW_SUNDAY && SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_WINDOWS_1900; } private static function buggyWeekNum1904(int $method, bool $origNull, DateTime $dateObject): bool { // This appears to be another Excel bug. - return $method === Constants::DOW_SUNDAY && Date::getExcelCalendar() === Date::CALENDAR_MAC_1904 && + return $method === Constants::DOW_SUNDAY && SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_MAC_1904 && !$origNull && $dateObject->format('Y-m-d') === '1904-01-01'; } } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php index ca8bd6b807..89e47b9690 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php @@ -2,9 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; class WorkDay { diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php index 18b259ed0f..da2ac12fc5 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php @@ -2,9 +2,9 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; -use Exception; +use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Shared\Date; +use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper; class YearFrac { @@ -72,7 +72,7 @@ public static function fraction($startDate, $endDate, $method = 0) */ private static function excelBug(float $sDate, $startDate, $endDate, int $method): float { - if (Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE && Date::getExcelCalendar() !== Date::CALENDAR_MAC_1904) { + if (Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE && SharedDateHelper::getExcelCalendar() !== SharedDateHelper::CALENDAR_MAC_1904) { if ($endDate === null && $startDate !== null) { if (DateParts::month($sDate) == 12 && DateParts::day($sDate) === 31 && $method === 0) { $sDate += 2;