Use correct Exception, ensure that Shared\Date is referenced by a synonym to ensure clarity, and ensure case-sensitivity for class references
This commit is contained in:
parent
765d4586ae
commit
9b34f8746b
|
|
@ -22,6 +22,7 @@ class Constants
|
||||||
const DOW_FRIDAY = 6;
|
const DOW_FRIDAY = 6;
|
||||||
const DOW_SATURDAY = 7;
|
const DOW_SATURDAY = 7;
|
||||||
const STARTWEEK_MONDAY_ISO = 21;
|
const STARTWEEK_MONDAY_ISO = 21;
|
||||||
|
|
||||||
const METHODARR = [
|
const METHODARR = [
|
||||||
self::STARTWEEK_SUNDAY => self::DOW_SUNDAY,
|
self::STARTWEEK_SUNDAY => self::DOW_SUNDAY,
|
||||||
self::DOW_MONDAY,
|
self::DOW_MONDAY,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||||
|
|
@ -102,7 +102,7 @@ class Date
|
||||||
$year += 1900;
|
$year += 1900;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $year;
|
return (int) $year;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class DateParts
|
class DateParts
|
||||||
{
|
{
|
||||||
|
|
@ -36,7 +36,7 @@ class DateParts
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
$PHPDateObject = Date::excelToDateTimeObject($dateValue);
|
$PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
|
||||||
|
|
||||||
return (int) $PHPDateObject->format('j');
|
return (int) $PHPDateObject->format('j');
|
||||||
}
|
}
|
||||||
|
|
@ -62,12 +62,12 @@ class DateParts
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
if ($dateValue < 1 && Date::getExcelCalendar() === DATE::CALENDAR_WINDOWS_1900) {
|
if ($dateValue < 1 && SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_WINDOWS_1900) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
$PHPDateObject = Date::excelToDateTimeObject($dateValue);
|
$PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
|
||||||
|
|
||||||
return (int) $PHPDateObject->format('n');
|
return (int) $PHPDateObject->format('n');
|
||||||
}
|
}
|
||||||
|
|
@ -94,11 +94,11 @@ class DateParts
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dateValue < 1 && Date::getExcelCalendar() === DATE::CALENDAR_WINDOWS_1900) {
|
if ($dateValue < 1 && SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_WINDOWS_1900) {
|
||||||
return 1900;
|
return 1900;
|
||||||
}
|
}
|
||||||
// Execute function
|
// Execute function
|
||||||
$PHPDateObject = Date::excelToDateTimeObject($dateValue);
|
$PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
|
||||||
|
|
||||||
return (int) $PHPDateObject->format('Y');
|
return (int) $PHPDateObject->format('Y');
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +110,7 @@ class DateParts
|
||||||
private static function weirdCondition($dateValue): int
|
private static function weirdCondition($dateValue): int
|
||||||
{
|
{
|
||||||
// Excel does not treat 0 consistently for DAY vs. (MONTH or YEAR)
|
// 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)) {
|
if (is_bool($dateValue)) {
|
||||||
return (int) $dateValue;
|
return (int) $dateValue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class DateValue
|
class DateValue
|
||||||
{
|
{
|
||||||
|
|
@ -36,7 +36,7 @@ class DateValue
|
||||||
public static function fromString($dateValue)
|
public static function fromString($dateValue)
|
||||||
{
|
{
|
||||||
$dti = new DateTimeImmutable();
|
$dti = new DateTimeImmutable();
|
||||||
$baseYear = Date::getExcelCalendar();
|
$baseYear = SharedDateHelper::getExcelCalendar();
|
||||||
$dateValue = trim(Functions::flattenSingleValue($dateValue), '"');
|
$dateValue = trim(Functions::flattenSingleValue($dateValue), '"');
|
||||||
// Strip any ordinals because they're allowed in Excel (English only)
|
// Strip any ordinals because they're allowed in Excel (English only)
|
||||||
$dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue) ?? '';
|
$dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue) ?? '';
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class Days
|
class Days
|
||||||
{
|
{
|
||||||
|
|
@ -34,8 +34,8 @@ class Days
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
$PHPStartDateObject = Date::excelToDateTimeObject($startDate);
|
$PHPStartDateObject = SharedDateHelper::excelToDateTimeObject($startDate);
|
||||||
$PHPEndDateObject = Date::excelToDateTimeObject($endDate);
|
$PHPEndDateObject = SharedDateHelper::excelToDateTimeObject($endDate);
|
||||||
|
|
||||||
$days = Functions::VALUE();
|
$days = Functions::VALUE();
|
||||||
$diff = $PHPStartDateObject->diff($PHPEndDateObject);
|
$diff = $PHPStartDateObject->diff($PHPEndDateObject);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class Days360
|
class Days360
|
||||||
{
|
{
|
||||||
|
|
@ -50,12 +50,12 @@ class Days360
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
$PHPStartDateObject = Date::excelToDateTimeObject($startDate);
|
$PHPStartDateObject = SharedDateHelper::excelToDateTimeObject($startDate);
|
||||||
$startDay = $PHPStartDateObject->format('j');
|
$startDay = $PHPStartDateObject->format('j');
|
||||||
$startMonth = $PHPStartDateObject->format('n');
|
$startMonth = $PHPStartDateObject->format('n');
|
||||||
$startYear = $PHPStartDateObject->format('Y');
|
$startYear = $PHPStartDateObject->format('Y');
|
||||||
|
|
||||||
$PHPEndDateObject = Date::excelToDateTimeObject($endDate);
|
$PHPEndDateObject = SharedDateHelper::excelToDateTimeObject($endDate);
|
||||||
$endDay = $PHPEndDateObject->format('j');
|
$endDay = $PHPEndDateObject->format('j');
|
||||||
$endMonth = $PHPEndDateObject->format('n');
|
$endMonth = $PHPEndDateObject->format('n');
|
||||||
$endYear = $PHPEndDateObject->format('Y');
|
$endYear = $PHPEndDateObject->format('Y');
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class Difference
|
class Difference
|
||||||
{
|
{
|
||||||
|
|
@ -33,12 +33,12 @@ class Difference
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
$PHPStartDateObject = Date::excelToDateTimeObject($startDate);
|
$PHPStartDateObject = SharedDateHelper::excelToDateTimeObject($startDate);
|
||||||
$startDays = (int) $PHPStartDateObject->format('j');
|
$startDays = (int) $PHPStartDateObject->format('j');
|
||||||
$startMonths = (int) $PHPStartDateObject->format('n');
|
$startMonths = (int) $PHPStartDateObject->format('n');
|
||||||
$startYears = (int) $PHPStartDateObject->format('Y');
|
$startYears = (int) $PHPStartDateObject->format('Y');
|
||||||
|
|
||||||
$PHPEndDateObject = Date::excelToDateTimeObject($endDate);
|
$PHPEndDateObject = SharedDateHelper::excelToDateTimeObject($endDate);
|
||||||
$endDays = (int) $PHPEndDateObject->format('j');
|
$endDays = (int) $PHPEndDateObject->format('j');
|
||||||
$endMonths = (int) $PHPEndDateObject->format('n');
|
$endMonths = (int) $PHPEndDateObject->format('n');
|
||||||
$endYears = (int) $PHPEndDateObject->format('Y');
|
$endYears = (int) $PHPEndDateObject->format('Y');
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class Helpers
|
class Helpers
|
||||||
{
|
{
|
||||||
|
|
@ -31,7 +31,7 @@ class Helpers
|
||||||
public static function getDateValue($dateValue, bool $allowBool = true): float
|
public static function getDateValue($dateValue, bool $allowBool = true): float
|
||||||
{
|
{
|
||||||
if (is_object($dateValue)) {
|
if (is_object($dateValue)) {
|
||||||
$retval = Date::PHPToExcel($dateValue);
|
$retval = SharedDateHelper::PHPToExcel($dateValue);
|
||||||
if (is_bool($retval)) {
|
if (is_bool($retval)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(Functions::VALUE());
|
||||||
}
|
}
|
||||||
|
|
@ -81,7 +81,7 @@ class Helpers
|
||||||
public static function adjustDateByMonths($dateValue = 0, float $adjustmentMonths = 0): DateTime
|
public static function adjustDateByMonths($dateValue = 0, float $adjustmentMonths = 0): DateTime
|
||||||
{
|
{
|
||||||
// Execute function
|
// Execute function
|
||||||
$PHPDateObject = Date::excelToDateTimeObject($dateValue);
|
$PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
|
||||||
$oMonth = (int) $PHPDateObject->format('m');
|
$oMonth = (int) $PHPDateObject->format('m');
|
||||||
$oYear = (int) $PHPDateObject->format('Y');
|
$oYear = (int) $PHPDateObject->format('Y');
|
||||||
|
|
||||||
|
|
@ -149,7 +149,7 @@ class Helpers
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$excelDateValue =
|
$excelDateValue =
|
||||||
Date::formattedPHPToExcel(
|
SharedDateHelper::formattedPHPToExcel(
|
||||||
$dateArray['year'],
|
$dateArray['year'],
|
||||||
$dateArray['month'],
|
$dateArray['month'],
|
||||||
$dateArray['day'],
|
$dateArray['day'],
|
||||||
|
|
@ -162,7 +162,7 @@ class Helpers
|
||||||
}
|
}
|
||||||
// RETURNDATE_UNIX_TIMESTAMP)
|
// RETURNDATE_UNIX_TIMESTAMP)
|
||||||
|
|
||||||
return (int) Date::excelToTimestamp($excelDateValue);
|
return (int) SharedDateHelper::excelToTimestamp($excelDateValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -177,11 +177,11 @@ class Helpers
|
||||||
return $excelDateValue;
|
return $excelDateValue;
|
||||||
}
|
}
|
||||||
if ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) {
|
if ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) {
|
||||||
return (int) Date::excelToTimestamp($excelDateValue);
|
return (int) SharedDateHelper::excelToTimestamp($excelDateValue);
|
||||||
}
|
}
|
||||||
// RETURNDATE_PHP_DATETIME_OBJECT
|
// RETURNDATE_PHP_DATETIME_OBJECT
|
||||||
|
|
||||||
return Date::excelToDateTimeObject($excelDateValue);
|
return SharedDateHelper::excelToDateTimeObject($excelDateValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -196,13 +196,13 @@ class Helpers
|
||||||
return $PHPDateObject;
|
return $PHPDateObject;
|
||||||
}
|
}
|
||||||
if ($retType === Functions::RETURNDATE_EXCEL) {
|
if ($retType === Functions::RETURNDATE_EXCEL) {
|
||||||
return (float) Date::PHPToExcel($PHPDateObject);
|
return (float) SharedDateHelper::PHPToExcel($PHPDateObject);
|
||||||
}
|
}
|
||||||
// RETURNDATE_UNIX_TIMESTAMP
|
// RETURNDATE_UNIX_TIMESTAMP
|
||||||
$stamp = Date::PHPToExcel($PHPDateObject);
|
$stamp = SharedDateHelper::PHPToExcel($PHPDateObject);
|
||||||
$stamp = is_bool($stamp) ? ((int) $stamp) : $stamp;
|
$stamp = is_bool($stamp) ? ((int) $stamp) : $stamp;
|
||||||
|
|
||||||
return (int) Date::excelToTimestamp($stamp);
|
return (int) SharedDateHelper::excelToTimestamp($stamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function baseDate(): int
|
private static function baseDate(): int
|
||||||
|
|
@ -210,7 +210,7 @@ class Helpers
|
||||||
if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) {
|
if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (Date::getExcelCalendar() === Date::CALENDAR_MAC_1904) {
|
if (SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_MAC_1904) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
|
||||||
|
|
||||||
class Month
|
class Month
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,8 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
|
||||||
|
|
||||||
class NetworkDays
|
class NetworkDays
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class Time
|
class Time
|
||||||
{
|
{
|
||||||
|
|
@ -57,13 +57,13 @@ class Time
|
||||||
// Execute function
|
// Execute function
|
||||||
$retType = Functions::getReturnDateType();
|
$retType = Functions::getReturnDateType();
|
||||||
if ($retType === Functions::RETURNDATE_EXCEL) {
|
if ($retType === Functions::RETURNDATE_EXCEL) {
|
||||||
$calendar = Date::getExcelCalendar();
|
$calendar = SharedDateHelper::getExcelCalendar();
|
||||||
$date = (int) ($calendar !== Date::CALENDAR_WINDOWS_1900);
|
$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) {
|
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
|
// RETURNDATE_PHP_DATETIME_OBJECT
|
||||||
// Hour has already been normalized (0-23) above
|
// Hour has already been normalized (0-23) above
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class TimeParts
|
class TimeParts
|
||||||
{
|
{
|
||||||
|
|
@ -37,7 +37,7 @@ class TimeParts
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
$timeValue = fmod($timeValue, 1);
|
$timeValue = fmod($timeValue, 1);
|
||||||
$timeValue = Date::excelToDateTimeObject($timeValue);
|
$timeValue = SharedDateHelper::excelToDateTimeObject($timeValue);
|
||||||
|
|
||||||
return (int) $timeValue->format('H');
|
return (int) $timeValue->format('H');
|
||||||
}
|
}
|
||||||
|
|
@ -71,7 +71,7 @@ class TimeParts
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
$timeValue = fmod($timeValue, 1);
|
$timeValue = fmod($timeValue, 1);
|
||||||
$timeValue = Date::excelToDateTimeObject($timeValue);
|
$timeValue = SharedDateHelper::excelToDateTimeObject($timeValue);
|
||||||
|
|
||||||
return (int) $timeValue->format('i');
|
return (int) $timeValue->format('i');
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +105,7 @@ class TimeParts
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
$timeValue = fmod($timeValue, 1);
|
$timeValue = fmod($timeValue, 1);
|
||||||
$timeValue = Date::excelToDateTimeObject($timeValue);
|
$timeValue = SharedDateHelper::excelToDateTimeObject($timeValue);
|
||||||
|
|
||||||
return (int) $timeValue->format('s');
|
return (int) $timeValue->format('s');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use Datetime;
|
use Datetime;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class TimeValue
|
class TimeValue
|
||||||
{
|
{
|
||||||
|
|
@ -44,13 +44,13 @@ class TimeValue
|
||||||
$retValue = Functions::VALUE();
|
$retValue = Functions::VALUE();
|
||||||
if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) {
|
if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) {
|
||||||
// OpenOffice-specific code removed - it works just like Excel
|
// 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();
|
$retType = Functions::getReturnDateType();
|
||||||
if ($retType === Functions::RETURNDATE_EXCEL) {
|
if ($retType === Functions::RETURNDATE_EXCEL) {
|
||||||
$retValue = (float) $excelDateValue;
|
$retValue = (float) $excelDateValue;
|
||||||
} elseif ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) {
|
} elseif ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) {
|
||||||
$retValue = (int) $phpDateValue = Date::excelToTimestamp($excelDateValue + 25569) - 3600;
|
$retValue = (int) $phpDateValue = SharedDateHelper::excelToTimestamp($excelDateValue + 25569) - 3600;
|
||||||
} else {
|
} else {
|
||||||
$retValue = new DateTime('1900-01-01 ' . $PHPDateArray['hour'] . ':' . $PHPDateArray['minute'] . ':' . $PHPDateArray['second']);
|
$retValue = new DateTime('1900-01-01 ' . $PHPDateArray['hour'] . ':' . $PHPDateArray['minute'] . ':' . $PHPDateArray['second']);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class Week
|
class Week
|
||||||
{
|
{
|
||||||
|
|
@ -45,7 +45,7 @@ class Week
|
||||||
try {
|
try {
|
||||||
$method = self::validateMethod($method);
|
$method = self::validateMethod($method);
|
||||||
if ($dateValue === null) { // boolean not allowed
|
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);
|
$dateValue = self::validateDateValue($dateValue);
|
||||||
if (!$dateValue && self::buggyWeekNum1900($method)) {
|
if (!$dateValue && self::buggyWeekNum1900($method)) {
|
||||||
|
|
@ -57,7 +57,7 @@ class Week
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
$PHPDateObject = Date::excelToDateTimeObject($dateValue);
|
$PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
|
||||||
if ($method == Constants::STARTWEEK_MONDAY_ISO) {
|
if ($method == Constants::STARTWEEK_MONDAY_ISO) {
|
||||||
Helpers::silly1900($PHPDateObject);
|
Helpers::silly1900($PHPDateObject);
|
||||||
|
|
||||||
|
|
@ -104,7 +104,7 @@ class Week
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
$PHPDateObject = Date::excelToDateTimeObject($dateValue);
|
$PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
|
||||||
Helpers::silly1900($PHPDateObject);
|
Helpers::silly1900($PHPDateObject);
|
||||||
|
|
||||||
return (int) $PHPDateObject->format('W');
|
return (int) $PHPDateObject->format('W');
|
||||||
|
|
@ -138,7 +138,7 @@ class Week
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute function
|
// Execute function
|
||||||
$PHPDateObject = Date::excelToDateTimeObject($dateValue);
|
$PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
|
||||||
Helpers::silly1900($PHPDateObject);
|
Helpers::silly1900($PHPDateObject);
|
||||||
$DoW = (int) $PHPDateObject->format('w');
|
$DoW = (int) $PHPDateObject->format('w');
|
||||||
|
|
||||||
|
|
@ -189,7 +189,7 @@ class Week
|
||||||
*/
|
*/
|
||||||
private static function apparentBug($dateValue): bool
|
private static function apparentBug($dateValue): bool
|
||||||
{
|
{
|
||||||
if (Date::getExcelCalendar() !== DATE::CALENDAR_MAC_1904) {
|
if (SharedDateHelper::getExcelCalendar() !== SharedDateHelper::CALENDAR_MAC_1904) {
|
||||||
if (is_bool($dateValue)) {
|
if (is_bool($dateValue)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -241,14 +241,14 @@ class Week
|
||||||
|
|
||||||
private static function buggyWeekNum1900(int $method): bool
|
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
|
private static function buggyWeekNum1904(int $method, bool $origNull, DateTime $dateObject): bool
|
||||||
{
|
{
|
||||||
// This appears to be another Excel bug.
|
// 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';
|
!$origNull && $dateObject->format('Y-m-d') === '1904-01-01';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,8 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
|
||||||
|
|
||||||
class WorkDay
|
class WorkDay
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
|
||||||
|
|
||||||
use Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
|
||||||
|
|
||||||
class YearFrac
|
class YearFrac
|
||||||
{
|
{
|
||||||
|
|
@ -72,7 +72,7 @@ class YearFrac
|
||||||
*/
|
*/
|
||||||
private static function excelBug(float $sDate, $startDate, $endDate, int $method): float
|
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 ($endDate === null && $startDate !== null) {
|
||||||
if (DateParts::month($sDate) == 12 && DateParts::day($sDate) === 31 && $method === 0) {
|
if (DateParts::month($sDate) == 12 && DateParts::day($sDate) === 31 && $method === 0) {
|
||||||
$sDate += 2;
|
$sDate += 2;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue