From 1e8ff9f8525a79d2b766c5d986936636735750dc Mon Sep 17 00:00:00 2001 From: oleibman Date: Sat, 24 Apr 2021 09:56:58 -0700 Subject: [PATCH] DateTimeExcel - Change Names of funcWhatever to evaluate (#2015) * DateTimeExcel - Change Names of funcWhatever to evaluate Per discussions while MathTrig was being broken up, this would help standardize the code. This PR applies that standardization to the DateTimeExcel family of functions. The deprecation messages in DateTime.php are changed to match the style used in PR #2005. All Phpstan grandfathered errors (about 25) in DateTimeExcel are fixed and removed from baseline. A small number (about 5) of phpstan annotations in the source members in that directory are also fixed and eliminated. --- phpstan-baseline.neon | 135 --------- .../Calculation/Calculation.php | 46 ++-- src/PhpSpreadsheet/Calculation/DateTime.php | 256 ++++++++++++------ .../Calculation/DateTimeExcel/DateDif.php | 2 +- .../Calculation/DateTimeExcel/DateValue.php | 12 +- .../Calculation/DateTimeExcel/Datefunc.php | 8 +- .../Calculation/DateTimeExcel/Day.php | 6 +- .../Calculation/DateTimeExcel/Days.php | 2 +- .../Calculation/DateTimeExcel/Days360.php | 2 +- .../Calculation/DateTimeExcel/EDate.php | 2 +- .../Calculation/DateTimeExcel/EoMonth.php | 2 +- .../Calculation/DateTimeExcel/Helpers.php | 20 +- .../Calculation/DateTimeExcel/Hour.php | 2 +- .../Calculation/DateTimeExcel/IsoWeekNum.php | 6 +- .../Calculation/DateTimeExcel/Minute.php | 2 +- .../Calculation/DateTimeExcel/Month.php | 2 +- .../Calculation/DateTimeExcel/NetworkDays.php | 11 +- .../Calculation/DateTimeExcel/Now.php | 2 +- .../Calculation/DateTimeExcel/Second.php | 2 +- .../Calculation/DateTimeExcel/Time.php | 11 +- .../Calculation/DateTimeExcel/TimeValue.php | 4 +- .../Calculation/DateTimeExcel/Today.php | 2 +- .../Calculation/DateTimeExcel/WeekDay.php | 7 +- .../Calculation/DateTimeExcel/WeekNum.php | 2 +- .../Calculation/DateTimeExcel/WorkDay.php | 32 ++- .../Calculation/DateTimeExcel/Year.php | 2 +- .../Calculation/DateTimeExcel/YearFrac.php | 26 +- .../Calculation/Financial/Amortization.php | 6 +- .../CashFlow/Variable/NonPeriodic.php | 5 +- .../Calculation/Financial/Coupons.php | 14 +- .../Financial/Securities/AccruedInterest.php | 6 +- .../Financial/Securities/Price.php | 12 +- .../Financial/Securities/Rates.php | 4 +- .../Financial/Securities/Yields.php | 12 +- .../Calculation/Financial/TreasuryBill.php | 6 +- .../Calculation/TextData/Format.php | 6 +- src/PhpSpreadsheet/Shared/Date.php | 4 +- src/PhpSpreadsheet/Worksheet/AutoFilter.php | 2 +- .../Functions/DateTime/DateTest.php | 8 +- .../Functions/DateTime/DateValueTest.php | 14 +- .../Functions/DateTime/DaysTest.php | 4 +- .../Functions/DateTime/EDateTest.php | 4 +- .../Functions/DateTime/EoMonthTest.php | 4 +- .../Functions/DateTime/TimeTest.php | 8 +- .../Functions/DateTime/TimeValueTest.php | 4 +- .../Functions/DateTime/WeekDayTest.php | 6 +- 46 files changed, 356 insertions(+), 379 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1b57a748..84fb7fd8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -340,141 +340,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTime\\:\\:NETWORKDAYS\\(\\) has parameter \\$dateArgs with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTime.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTime\\:\\:WORKDAY\\(\\) has parameter \\$dateArgs with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTime.php - - - - message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, string\\|null given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php - - - - message: "#^Parameter \\#1 \\$haystack of function strpos expects string, float\\|int\\|string given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php - - - - message: "#^Parameter \\#1 \\$PHPDateArray of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\DateValue\\:\\:finalResults\\(\\) expects array\\|false, array\\|bool given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php - - - - message: "#^Parameter \\#1 \\$testVal1 of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:adjustYear\\(\\) expects string, string\\|false given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php - - - - message: "#^Parameter \\#2 \\$testVal2 of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:adjustYear\\(\\) expects string, string\\|false given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php - - - - message: "#^Parameter \\#1 \\$value of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:testStringAsNumeric\\(\\) expects string, float\\|int\\|string given\\.$#" - count: 2 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Datefunc.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Day\\:\\:weirdCondition\\(\\) has parameter \\$dateValue with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Day.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:adjustDateByMonths\\(\\) has no return typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:adjustDateByMonths\\(\\) has parameter \\$adjustmentMonths with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:adjustDateByMonths\\(\\) has parameter \\$dateValue with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php - - - - message: "#^Parameter \\#1 \\$excelTimestamp of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Date\\:\\:excelToTimestamp\\(\\) expects float\\|int, bool\\|float given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:validateNumericNull\\(\\) should return float\\|int but returns float\\|int\\|string\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\IsoWeekNum\\:\\:apparentBug\\(\\) has parameter \\$dateValue with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/IsoWeekNum.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\NetworkDays\\:\\:funcNetworkDays\\(\\) has parameter \\$dateArgs with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\NetworkDays\\:\\:applySign\\(\\) has no return typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Time\\:\\:toIntWithNullBool\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php - - - - message: "#^Cannot access offset 0 on array\\\\|false\\.$#" - count: 3 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php - - - - message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, array\\\\|false given\\.$#" - count: 2 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\WeekDay\\:\\:validateStyle\\(\\) has parameter \\$style with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekDay.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\WorkDay\\:\\:funcWorkDay\\(\\) has parameter \\$dateArgs with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php - - - - message: "#^Binary operation \"\\-\" between 7 and int\\|string results in an error\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php - - - - message: "#^Binary operation \"\\-\" between 7 and int\\<5, max\\>\\|string results in an error\\.$#" - count: 2 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php - - - - message: "#^Binary operation \"\\-\" between 4 and int\\<5, max\\>\\|string results in an error\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php - - - - message: "#^Binary operation \"\\-\" between int\\|string and int\\|string results in an error\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php - - - - message: "#^Binary operation \"\\*\" between 100 and int\\|string results in an error\\.$#" - count: 2 - path: src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engine\\\\Logger\\:\\:writeDebugLog\\(\\) has parameter \\$args with no typehint specified\\.$#" count: 1 diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index ec85df69..97bd1779 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -755,17 +755,17 @@ class Calculation ], 'DATE' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\Datefunc::class, 'funcDate'], + 'functionCall' => [DateTimeExcel\Datefunc::class, 'evaluate'], 'argumentCount' => '3', ], 'DATEDIF' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\DateDif::class, 'funcDateDif'], + 'functionCall' => [DateTimeExcel\DateDif::class, 'evaluate'], 'argumentCount' => '2,3', ], 'DATEVALUE' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\DateValue::class, 'funcDateValue'], + 'functionCall' => [DateTimeExcel\DateValue::class, 'evaluate'], 'argumentCount' => '1', ], 'DAVERAGE' => [ @@ -775,17 +775,17 @@ class Calculation ], 'DAY' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\Day::class, 'funcDay'], + 'functionCall' => [DateTimeExcel\Day::class, 'evaluate'], 'argumentCount' => '1', ], 'DAYS' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\Days::class, 'funcDays'], + 'functionCall' => [DateTimeExcel\Days::class, 'evaluate'], 'argumentCount' => '2', ], 'DAYS360' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\Days360::class, 'funcDays360'], + 'functionCall' => [DateTimeExcel\Days360::class, 'evaluate'], 'argumentCount' => '2,3', ], 'DB' => [ @@ -920,7 +920,7 @@ class Calculation ], 'EDATE' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\EDate::class, 'funcEDate'], + 'functionCall' => [DateTimeExcel\EDate::class, 'evaluate'], 'argumentCount' => '2', ], 'EFFECT' => [ @@ -935,7 +935,7 @@ class Calculation ], 'EOMONTH' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\EoMonth::class, 'funcEoMonth'], + 'functionCall' => [DateTimeExcel\EoMonth::class, 'evaluate'], 'argumentCount' => '2', ], 'ERF' => [ @@ -1237,7 +1237,7 @@ class Calculation ], 'HOUR' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\Hour::class, 'funcHour'], + 'functionCall' => [DateTimeExcel\Hour::class, 'evaluate'], 'argumentCount' => '1', ], 'HYPERLINK' => [ @@ -1501,7 +1501,7 @@ class Calculation ], 'ISOWEEKNUM' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\IsoWeekNum::class, 'funcIsoWeekNum'], + 'functionCall' => [DateTimeExcel\IsoWeekNum::class, 'evaluate'], 'argumentCount' => '1', ], 'ISPMT' => [ @@ -1681,7 +1681,7 @@ class Calculation ], 'MINUTE' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\Minute::class, 'funcMinute'], + 'functionCall' => [DateTimeExcel\Minute::class, 'evaluate'], 'argumentCount' => '1', ], 'MINVERSE' => [ @@ -1721,7 +1721,7 @@ class Calculation ], 'MONTH' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\Month::class, 'funcMonth'], + 'functionCall' => [DateTimeExcel\Month::class, 'evaluate'], 'argumentCount' => '1', ], 'MROUND' => [ @@ -1761,7 +1761,7 @@ class Calculation ], 'NETWORKDAYS' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\NetworkDays::class, 'funcNetworkDays'], + 'functionCall' => [DateTimeExcel\NetworkDays::class, 'evaluate'], 'argumentCount' => '2-3', ], 'NETWORKDAYS.INTL' => [ @@ -1821,7 +1821,7 @@ class Calculation ], 'NOW' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\Now::class, 'funcNow'], + 'functionCall' => [DateTimeExcel\Now::class, 'evaluate'], 'argumentCount' => '0', ], 'NPER' => [ @@ -2175,7 +2175,7 @@ class Calculation ], 'SECOND' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\Second::class, 'funcSecond'], + 'functionCall' => [DateTimeExcel\Second::class, 'evaluate'], 'argumentCount' => '1', ], 'SEQUENCE' => [ @@ -2421,12 +2421,12 @@ class Calculation ], 'TIME' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\Time::class, 'funcTime'], + 'functionCall' => [DateTimeExcel\Time::class, 'evaluate'], 'argumentCount' => '3', ], 'TIMEVALUE' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\TimeValue::class, 'funcTimeValue'], + 'functionCall' => [DateTimeExcel\TimeValue::class, 'evaluate'], 'argumentCount' => '1', ], 'TINV' => [ @@ -2446,7 +2446,7 @@ class Calculation ], 'TODAY' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\Today::class, 'funcToday'], + 'functionCall' => [DateTimeExcel\Today::class, 'evaluate'], 'argumentCount' => '0', ], 'TRANSPOSE' => [ @@ -2571,12 +2571,12 @@ class Calculation ], 'WEEKDAY' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\WeekDay::class, 'funcWeekDay'], + 'functionCall' => [DateTimeExcel\WeekDay::class, 'evaluate'], 'argumentCount' => '1,2', ], 'WEEKNUM' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\WeekNum::class, 'funcWeekNum'], + 'functionCall' => [DateTimeExcel\WeekNum::class, 'evaluate'], 'argumentCount' => '1,2', ], 'WEIBULL' => [ @@ -2591,7 +2591,7 @@ class Calculation ], 'WORKDAY' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\WorkDay::class, 'funcWorkDay'], + 'functionCall' => [DateTimeExcel\WorkDay::class, 'evaluate'], 'argumentCount' => '2-3', ], 'WORKDAY.INTL' => [ @@ -2626,12 +2626,12 @@ class Calculation ], 'YEAR' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\Year::class, 'funcYear'], + 'functionCall' => [DateTimeExcel\Year::class, 'evaluate'], 'argumentCount' => '1', ], 'YEARFRAC' => [ 'category' => Category::CATEGORY_DATE_AND_TIME, - 'functionCall' => [DateTimeExcel\YearFrac::class, 'funcYearFrac'], + 'functionCall' => [DateTimeExcel\YearFrac::class, 'evaluate'], 'argumentCount' => '2,3', ], 'YIELD' => [ diff --git a/src/PhpSpreadsheet/Calculation/DateTime.php b/src/PhpSpreadsheet/Calculation/DateTime.php index 7643ed0b..c0a38f56 100644 --- a/src/PhpSpreadsheet/Calculation/DateTime.php +++ b/src/PhpSpreadsheet/Calculation/DateTime.php @@ -9,7 +9,10 @@ class DateTime /** * Identify if a year is a leap year or not. * - * @Deprecated 2.0.0 Use the method isLeapYear in the DateTimeExcel\Helpers class instead + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Helpers::isLeapYear() + * Use the isLeapYear method in the DateTimeExcel\Helpers class instead * * @param int|string $year The year to test * @@ -23,7 +26,10 @@ class DateTime /** * getDateValue. * - * @Deprecated 2.0.0 Use the method getDateValue in the DateTimeExcel\Helpers class instead + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Helpers::getDateValue() + * Use the getDateValue method in the DateTimeExcel\Helpers class instead * * @param mixed $dateValue * @@ -49,17 +55,20 @@ class DateTime * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date * and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. * - * @Deprecated 2.0.0 Use the funcNow method in the DateTimeExcel\Now class instead - * * Excel Function: * NOW() * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Now::evaluate() + * Use the evaluate method in the DateTimeExcel\Now class instead + * * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ public static function DATETIMENOW() { - return DateTimeExcel\Now::funcNow(); + return DateTimeExcel\Now::evaluate(); } /** @@ -73,17 +82,20 @@ class DateTime * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date * and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. * - * @Deprecated 2.0.0 Use the funcToday method in the DateTimeExcel\Today class instead - * * Excel Function: * TODAY() * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Today::evaluate() + * Use the evaluate method in the DateTimeExcel\Today class instead + * * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ public static function DATENOW() { - return DateTimeExcel\Today::funcToday(); + return DateTimeExcel\Today::evaluate(); } /** @@ -94,11 +106,15 @@ class DateTime * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date * format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. * - * @Deprecated 2.0.0 Use the funcDate method in the DateTimeExcel\Date class instead * * Excel Function: * DATE(year,month,day) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Datefunc::evaluate() + * Use the evaluate method in the DateTimeExcel\Datefunc class instead + * * PhpSpreadsheet is a lot more forgiving than MS Excel when passing non numeric values to this function. * A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted, * as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language. @@ -139,7 +155,7 @@ class DateTime */ public static function DATE($year = 0, $month = 1, $day = 1) { - return DateTimeExcel\Datefunc::funcDate($year, $month, $day); + return DateTimeExcel\Datefunc::evaluate($year, $month, $day); } /** @@ -150,11 +166,14 @@ class DateTime * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time * format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. * - * @Deprecated 2.0.0 Use the funcTime method in the DateTimeExcel\Time class instead - * * Excel Function: * TIME(hour,minute,second) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Time::evaluate() + * Use the evaluate method in the DateTimeExcel\Time class instead + * * @param int $hour A number from 0 (zero) to 32767 representing the hour. * Any value greater than 23 will be divided by 24 and the remainder * will be treated as the hour value. For example, TIME(27,0,0) = @@ -172,7 +191,7 @@ class DateTime */ public static function TIME($hour = 0, $minute = 0, $second = 0) { - return DateTimeExcel\Time::funcTime($hour, $minute, $second); + return DateTimeExcel\Time::evaluate($hour, $minute, $second); } /** @@ -185,11 +204,14 @@ class DateTime * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date * format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. * - * @Deprecated 2.0.0 Use the funcDateValue method in the DateTimeExcel\DateValue class instead - * * Excel Function: * DATEVALUE(dateValue) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\DateValue::evaluate() + * Use the evaluate method in the DateTimeExcel\DateValue class instead + * * @param string $dateValue Text that represents a date in a Microsoft Excel date format. * For example, "1/30/2008" or "30-Jan-2008" are text strings within * quotation marks that represent dates. Using the default date @@ -204,7 +226,7 @@ class DateTime */ public static function DATEVALUE($dateValue) { - return DateTimeExcel\DateValue::funcDateValue($dateValue); + return DateTimeExcel\DateValue::evaluate($dateValue); } /** @@ -217,11 +239,14 @@ class DateTime * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time * format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. * - * @Deprecated 2.0.0 Use the funcTimeValue method in the DateTimeExcel\TimeValue class instead - * * Excel Function: * TIMEVALUE(timeValue) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\TimeValue::evaluate() + * Use the evaluate method in the DateTimeExcel\TimeValue class instead + * * @param string $timeValue A text string that represents a time in any one of the Microsoft * Excel time formats; for example, "6:45 PM" and "18:45" text strings * within quotation marks that represent time. @@ -232,13 +257,19 @@ class DateTime */ public static function TIMEVALUE($timeValue) { - return DateTimeExcel\TimeValue::funcTimeValue($timeValue); + return DateTimeExcel\TimeValue::evaluate($timeValue); } /** * DATEDIF. * - * @Deprecated 2.0.0 Use the funcDateDif method in the DateTimeExcel\DateDif class instead + * Excel Function: + * DATEDIF(startdate, enddate, unit) + * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\DateDif::evaluate() + * Use the evaluate method in the DateTimeExcel\DateDif class instead * * @param mixed $startDate Excel date serial value, PHP date/time stamp, PHP DateTime object * or a standard date string @@ -250,7 +281,7 @@ class DateTime */ public static function DATEDIF($startDate = 0, $endDate = 0, $unit = 'D') { - return DateTimeExcel\DateDif::funcDateDif($startDate, $endDate, $unit); + return DateTimeExcel\DateDif::evaluate($startDate, $endDate, $unit); } /** @@ -258,11 +289,14 @@ class DateTime * * Returns the number of days between two dates * - * @Deprecated 2.0.0 Use the funcDays method in the DateTimeExcel\Days class instead - * * Excel Function: * DAYS(endDate, startDate) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Days::evaluate() + * Use the evaluate method in the DateTimeExcel\Days class instead + * * @param DateTimeInterface|float|int|string $endDate Excel date serial value (float), * PHP date timestamp (integer), PHP DateTime object, or a standard date string * @param DateTimeInterface|float|int|string $startDate Excel date serial value (float), @@ -272,7 +306,7 @@ class DateTime */ public static function DAYS($endDate = 0, $startDate = 0) { - return DateTimeExcel\Days::funcDays($endDate, $startDate); + return DateTimeExcel\Days::evaluate($endDate, $startDate); } /** @@ -282,11 +316,14 @@ class DateTime * which is used in some accounting calculations. Use this function to help compute payments if * your accounting system is based on twelve 30-day months. * - * @Deprecated 2.0.0 Use the funcDays360 method in the DateTimeExcel\Days360 class instead - * * Excel Function: * DAYS360(startDate,endDate[,method]) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Days360::evaluate() + * Use the evaluate method in the DateTimeExcel\Days360 class instead + * * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer), @@ -307,7 +344,7 @@ class DateTime */ public static function DAYS360($startDate = 0, $endDate = 0, $method = false) { - return DateTimeExcel\Days360::funcDays360($startDate, $endDate, $method); + return DateTimeExcel\Days360::evaluate($startDate, $endDate, $method); } /** @@ -318,10 +355,14 @@ class DateTime * Use the YEARFRAC worksheet function to identify the proportion of a whole year's benefits or * obligations to assign to a specific term. * - * @Deprecated 2.0.0 Use the funcYearFrac method in the DateTimeExcel\YearFrac class instead - * * Excel Function: * YEARFRAC(startDate,endDate[,method]) + * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\YearFrac::evaluate() + * Use the evaluate method in the DateTimeExcel\YearFrac class instead + * * See https://lists.oasis-open.org/archives/office-formula/200806/msg00039.html * for description of algorithm used in Excel * @@ -340,7 +381,7 @@ class DateTime */ public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0) { - return DateTimeExcel\YearFrac::funcYearFrac($startDate, $endDate, $method); + return DateTimeExcel\YearFrac::evaluate($startDate, $endDate, $method); } /** @@ -351,21 +392,25 @@ class DateTime * Use NETWORKDAYS to calculate employee benefits that accrue based on the number of days * worked during a specific term. * - * @Deprecated 2.0.0 Use the funcNetworkDays method in the DateTimeExcel\NetworkDays class instead - * * Excel Function: * NETWORKDAYS(startDate,endDate[,holidays[,holiday[,...]]]) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\NetworkDays::evaluate() + * Use the evaluate method in the DateTimeExcel\NetworkDays class instead + * * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string + * @param mixed $dateArgs * * @return int|string Interval between the dates */ public static function NETWORKDAYS($startDate, $endDate, ...$dateArgs) { - return DateTimeExcel\NetworkDays::funcNetworkDays($startDate, $endDate, ...$dateArgs); + return DateTimeExcel\NetworkDays::evaluate($startDate, $endDate, ...$dateArgs); } /** @@ -376,23 +421,27 @@ class DateTime * Use WORKDAY to exclude weekends or holidays when you calculate invoice due dates, expected * delivery times, or the number of days of work performed. * - * @Deprecated 2.0.0 Use the funcWorkDay method in the DateTimeExcel\WorkDay class instead - * * Excel Function: * WORKDAY(startDate,endDays[,holidays[,holiday[,...]]]) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\WorkDay::evaluate() + * Use the evaluate method in the DateTimeExcel\WorkDay class instead + * * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param int $endDays The number of nonweekend and nonholiday days before or after * startDate. A positive value for days yields a future date; a * negative value yields a past date. + * @param mixed $dateArgs * * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ public static function WORKDAY($startDate, $endDays, ...$dateArgs) { - return DateTimeExcel\WorkDay::funcWorkDay($startDate, $endDays, ...$dateArgs); + return DateTimeExcel\WorkDay::evaluate($startDate, $endDays, ...$dateArgs); } /** @@ -401,11 +450,14 @@ class DateTime * Returns the day of the month, for a specified date. The day is given as an integer * ranging from 1 to 31. * - * @Deprecated 2.0.0 Use the funcDay method in the DateTimeExcel\Day class instead - * * Excel Function: * DAY(dateValue) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Day::evaluate() + * Use the evaluate method in the DateTimeExcel\Day class instead + * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @@ -413,7 +465,7 @@ class DateTime */ public static function DAYOFMONTH($dateValue = 1) { - return DateTimeExcel\Day::funcDay($dateValue); + return DateTimeExcel\Day::evaluate($dateValue); } /** @@ -422,11 +474,14 @@ class DateTime * Returns the day of the week for a specified date. The day is given as an integer * ranging from 0 to 7 (dependent on the requested style). * - * @Deprecated 2.0.0 Use the funcWeekDay method in the DateTimeExcel\WeekDay class instead - * * Excel Function: * WEEKDAY(dateValue[,style]) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\WeekDay::evaluate() + * Use the evaluate method in the DateTimeExcel\WeekDay class instead + * * @param float|int|string $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param int $style A number that determines the type of return value @@ -438,13 +493,13 @@ class DateTime */ public static function WEEKDAY($dateValue = 1, $style = 1) { - return DateTimeExcel\WeekDay::funcWeekDay($dateValue, $style); + return DateTimeExcel\WeekDay::evaluate($dateValue, $style); } /** * STARTWEEK_SUNDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\STARTWEEK_SUNDAY instead */ @@ -453,7 +508,7 @@ class DateTime /** * STARTWEEK_MONDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\STARTWEEK_MONDAY instead */ @@ -462,7 +517,7 @@ class DateTime /** * STARTWEEK_MONDAY_ALT. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\STARTWEEK_MONDAY_ALT instead */ @@ -471,7 +526,7 @@ class DateTime /** * STARTWEEK_TUESDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\STARTWEEK_TUESDAY instead */ @@ -480,7 +535,7 @@ class DateTime /** * STARTWEEK_WEDNESDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\STARTWEEK_WEDNESDAY instead */ @@ -489,7 +544,7 @@ class DateTime /** * STARTWEEK_THURSDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\STARTWEEK_THURSDAY instead */ @@ -498,7 +553,7 @@ class DateTime /** * STARTWEEK_FRIDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\STARTWEEK_FRIDAY instead */ @@ -507,7 +562,7 @@ class DateTime /** * STARTWEEK_SATURDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\STARTWEEK_SATURDAY instead */ @@ -516,7 +571,7 @@ class DateTime /** * STARTWEEK_SUNDAY_ALT. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\STARTWEEK_SUNDAY_ALT instead */ @@ -525,7 +580,7 @@ class DateTime /** * DOW_SUNDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\DOW_SUNDAY instead */ @@ -534,7 +589,7 @@ class DateTime /** * DOW_MONDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\DOW_MONDAY instead */ @@ -543,7 +598,7 @@ class DateTime /** * DOW_TUESDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\DOW_TUESDAY instead */ @@ -552,7 +607,7 @@ class DateTime /** * DOW_WEDNESDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\DOW_WEDNESDAY instead */ @@ -561,7 +616,7 @@ class DateTime /** * DOW_THURSDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\DOW_THURSDAY instead */ @@ -570,7 +625,7 @@ class DateTime /** * DOW_FRIDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\DOW_FRIDAY instead */ @@ -579,7 +634,7 @@ class DateTime /** * DOW_SATURDAY. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\DOW_SATURDAY instead */ @@ -588,7 +643,7 @@ class DateTime /** * STARTWEEK_MONDAY_ISO. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\STARTWEEK_MONDAY_ISO instead */ @@ -597,7 +652,7 @@ class DateTime /** * METHODARR. * - * @Deprecated 2.0.0 + * @Deprecated 1.18.0 * * @see Use DateTimeExcel\Constants\METHODARR instead */ @@ -624,11 +679,14 @@ class DateTime * three days or less in the first week of January, the WEEKNUM function returns week numbers * that are incorrect according to the European standard. * - * @Deprecated 2.0.0 Use the funcWeekNum method in the DateTimeExcel\WeekNum class instead - * * Excel Function: * WEEKNUM(dateValue[,style]) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\WeekNum::evaluate() + * Use the evaluate method in the DateTimeExcel\WeekNum class instead + * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param int $method Week begins on Sunday or Monday @@ -647,7 +705,7 @@ class DateTime */ public static function WEEKNUM($dateValue = 1, $method = self::STARTWEEK_SUNDAY) { - return DateTimeExcel\WeekNum::funcWeekNum($dateValue, $method); + return DateTimeExcel\WeekNum::evaluate($dateValue, $method); } /** @@ -655,11 +713,14 @@ class DateTime * * Returns the ISO 8601 week number of the year for a specified date. * - * @Deprecated 2.0.0 Use the funcIsoWeeknum method in the DateTimeExcel\IsoWeekNum class instead - * * Excel Function: * ISOWEEKNUM(dateValue) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\IsoWeekNum::evaluate() + * Use the evaluate method in the DateTimeExcel\IsoWeekNum class instead + * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @@ -667,7 +728,7 @@ class DateTime */ public static function ISOWEEKNUM($dateValue = 1) { - return DateTimeExcel\IsoWeekNum::funcIsoWeekNum($dateValue); + return DateTimeExcel\IsoWeekNum::evaluate($dateValue); } /** @@ -676,11 +737,14 @@ class DateTime * Returns the month of a date represented by a serial number. * The month is given as an integer, ranging from 1 (January) to 12 (December). * - * @Deprecated 2.0.0 Use the funcMonth method in the DateTimeExcel\Month class instead - * * Excel Function: * MONTH(dateValue) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Month::evaluate() + * Use the evaluate method in the DateTimeExcel\Month class instead + * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @@ -688,7 +752,7 @@ class DateTime */ public static function MONTHOFYEAR($dateValue = 1) { - return DateTimeExcel\Month::funcMonth($dateValue); + return DateTimeExcel\Month::evaluate($dateValue); } /** @@ -697,11 +761,14 @@ class DateTime * Returns the year corresponding to a date. * The year is returned as an integer in the range 1900-9999. * - * @Deprecated 2.0.0 Use the funcYear method in the DateTimeExcel\Year class instead - * * Excel Function: * YEAR(dateValue) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Year::evaluate() + * Use the evaluate method in the DateTimeExcel\Year class instead + * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @@ -709,7 +776,7 @@ class DateTime */ public static function YEAR($dateValue = 1) { - return DateTimeExcel\Year::funcYear($dateValue); + return DateTimeExcel\Year::evaluate($dateValue); } /** @@ -718,11 +785,14 @@ class DateTime * Returns the hour of a time value. * The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.). * - * @Deprecated 2.0.0 Use the funcHour method in the DateTimeExcel\Hour class instead - * * Excel Function: * HOUR(timeValue) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Hour::evaluate() + * Use the evaluate method in the DateTimeExcel\Hour class instead + * * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard time string * @@ -730,7 +800,7 @@ class DateTime */ public static function HOUROFDAY($timeValue = 0) { - return DateTimeExcel\Hour::funcHour($timeValue); + return DateTimeExcel\Hour::evaluate($timeValue); } /** @@ -739,11 +809,14 @@ class DateTime * Returns the minutes of a time value. * The minute is given as an integer, ranging from 0 to 59. * - * @Deprecated 2.0.0 Use the funcMinute method in the DateTimeExcel\Minute class instead - * * Excel Function: * MINUTE(timeValue) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Minute::evaluate() + * Use the evaluate method in the DateTimeExcel\Minute class instead + * * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard time string * @@ -751,7 +824,7 @@ class DateTime */ public static function MINUTE($timeValue = 0) { - return DateTimeExcel\Minute::funcMinute($timeValue); + return DateTimeExcel\Minute::evaluate($timeValue); } /** @@ -760,11 +833,14 @@ class DateTime * Returns the seconds of a time value. * The second is given as an integer in the range 0 (zero) to 59. * - * @Deprecated 2.0.0 Use the funcSecond method in the DateTimeExcel\Second class instead - * * Excel Function: * SECOND(timeValue) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Second::evaluate() + * Use the evaluate method in the DateTimeExcel\Second class instead + * * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard time string * @@ -772,7 +848,7 @@ class DateTime */ public static function SECOND($timeValue = 0) { - return DateTimeExcel\Second::funcSecond($timeValue); + return DateTimeExcel\Second::evaluate($timeValue); } /** @@ -783,11 +859,14 @@ class DateTime * Use EDATE to calculate maturity dates or due dates that fall on the same day of the month * as the date of issue. * - * @Deprecated 2.0.0 Use the funcEDate method in the DateTimeExcel\EDate class instead - * * Excel Function: * EDATE(dateValue,adjustmentMonths) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\Edate::evaluate() + * Use the evaluate method in the DateTimeExcel\Edate class instead + * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param int $adjustmentMonths The number of months before or after start_date. @@ -799,7 +878,7 @@ class DateTime */ public static function EDATE($dateValue = 1, $adjustmentMonths = 0) { - return DateTimeExcel\EDate::funcEDate($dateValue, $adjustmentMonths); + return DateTimeExcel\EDate::evaluate($dateValue, $adjustmentMonths); } /** @@ -809,11 +888,14 @@ class DateTime * before or after start_date. * Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month. * - * @Deprecated 2.0.0 Use the funcEoMonth method in the DateTimeExcel\EoMonth class instead - * * Excel Function: * EOMONTH(dateValue,adjustmentMonths) * + * @Deprecated 1.18.0 + * + * @See DateTimeExcel\EoMonth::evaluate() + * Use the evaluate method in the DateTimeExcel\EoMonth class instead + * * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string * @param int $adjustmentMonths The number of months before or after start_date. @@ -825,6 +907,6 @@ class DateTime */ public static function EOMONTH($dateValue = 1, $adjustmentMonths = 0) { - return DateTimeExcel\EoMonth::funcEoMonth($dateValue, $adjustmentMonths); + return DateTimeExcel\EoMonth::evaluate($dateValue, $adjustmentMonths); } } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateDif.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateDif.php index c0d1fa4b..26eb1dbf 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateDif.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateDif.php @@ -21,7 +21,7 @@ class DateDif * * @return int|string Interval between the dates */ - public static function funcDateDif($startDate, $endDate, $unit = 'D') + public static function evaluate($startDate, $endDate, $unit = 'D') { try { $startDate = Helpers::getDateValue($startDate); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php index 86b8d3d9..ee872f31 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php @@ -33,13 +33,13 @@ class DateValue * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function funcDateValue($dateValue) + public static function evaluate($dateValue) { $dti = new DateTimeImmutable(); $baseYear = Date::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); + $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue) ?? ''; // Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany) $dateValue = str_replace(['/', '.', '-', ' '], ' ', $dateValue); @@ -59,7 +59,7 @@ class DateValue } if (count($t1) === 1) { // We've been fed a time value without any date - return ((strpos($t, ':') === false)) ? Functions::Value() : 0.0; + return ((strpos((string) $t, ':') === false)) ? Functions::Value() : 0.0; } unset($t); @@ -105,7 +105,7 @@ class DateValue $testVal1 = strtok($dateValue, '- '); $testVal2 = strtok('- '); $testVal3 = strtok('- ') ?: $dti->format('Y'); - Helpers::adjustYear($testVal1, $testVal2, $testVal3); + Helpers::adjustYear((string) $testVal1, (string) $testVal2, $testVal3); $PHPDateArray = date_parse($testVal1 . '-' . $testVal2 . '-' . $testVal3); if (($PHPDateArray === false) || ($PHPDateArray['error_count'] > 0)) { $PHPDateArray = date_parse($testVal2 . '-' . $testVal1 . '-' . $testVal3); @@ -118,7 +118,7 @@ class DateValue /** * Final results. * - * @param array|false $PHPDateArray + * @param array|bool $PHPDateArray * * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag @@ -126,7 +126,7 @@ class DateValue private static function finalResults($PHPDateArray, DateTimeImmutable $dti, int $baseYear) { $retValue = Functions::Value(); - if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) { + if (is_array($PHPDateArray) && $PHPDateArray['error_count'] == 0) { // Execute function Helpers::replaceIfEmpty($PHPDateArray['year'], $dti->format('Y')); if ($PHPDateArray['year'] < $baseYear) { diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Datefunc.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Datefunc.php index ec8be2df..e8aa02cb 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Datefunc.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Datefunc.php @@ -58,7 +58,7 @@ class Datefunc * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function funcDate($year, $month, $day) + public static function evaluate($year, $month, $day) { $baseYear = Date::getExcelCalendar(); @@ -85,7 +85,7 @@ class Datefunc private static function getYear($year, int $baseYear): int { $year = Functions::flattenSingleValue($year); - $year = ($year !== null) ? StringHelper::testStringAsNumeric($year) : 0; + $year = ($year !== null) ? StringHelper::testStringAsNumeric((string) $year) : 0; if (!is_numeric($year)) { throw new Exception(Functions::VALUE()); } @@ -118,7 +118,7 @@ class Datefunc $month = Date::monthStringToNumber($month); } - $month = ($month !== null) ? StringHelper::testStringAsNumeric($month) : 0; + $month = ($month !== null) ? StringHelper::testStringAsNumeric((string) $month) : 0; if (!is_numeric($month)) { throw new Exception(Functions::VALUE()); } @@ -139,7 +139,7 @@ class Datefunc $day = Date::dayStringToNumber($day); } - $day = ($day !== null) ? StringHelper::testStringAsNumeric($day) : 0; + $day = ($day !== null) ? StringHelper::testStringAsNumeric((string) $day) : 0; if (!is_numeric($day)) { throw new Exception(Functions::VALUE()); } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Day.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Day.php index 6ab27184..bc57644d 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Day.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Day.php @@ -22,7 +22,7 @@ class Day * * @return int|string Day of the month */ - public static function funcDay($dateValue) + public static function evaluate($dateValue) { $weirdResult = self::weirdCondition($dateValue); if ($weirdResult >= 0) { @@ -41,6 +41,10 @@ class Day return (int) $PHPDateObject->format('j'); } + /** + * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), + * PHP DateTime object, or a standard date string + */ private static function weirdCondition($dateValue): int { // Excel does not treat 0 consistently for DAY vs. (MONTH or YEAR) diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php index 2c814e8e..bd37e481 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php @@ -24,7 +24,7 @@ class Days * * @return int|string Number of days between start date and end date or an error */ - public static function funcDays($endDate, $startDate) + public static function evaluate($endDate, $startDate) { try { $startDate = Helpers::getDateValue($startDate); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php index 47de02c3..74de95ad 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php @@ -36,7 +36,7 @@ class Days360 * * @return int|string Number of days between start date and end date */ - public static function funcDays360($startDate = 0, $endDate = 0, $method = false) + public static function evaluate($startDate = 0, $endDate = 0, $method = false) { try { $startDate = Helpers::getDateValue($startDate); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/EDate.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/EDate.php index 43af694f..bb234097 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/EDate.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/EDate.php @@ -27,7 +27,7 @@ class EDate * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function funcEDate($dateValue, $adjustmentMonths) + public static function evaluate($dateValue, $adjustmentMonths) { try { $dateValue = Helpers::getDateValue($dateValue, false); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/EoMonth.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/EoMonth.php index 6b39a609..54449c5d 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/EoMonth.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/EoMonth.php @@ -26,7 +26,7 @@ class EoMonth * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function funcEoMonth($dateValue, $adjustmentMonths) + public static function evaluate($dateValue, $adjustmentMonths) { try { $dateValue = Helpers::getDateValue($dateValue, false); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php index 5b3a8067..00f12ddc 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php @@ -43,7 +43,7 @@ class Helpers if (!is_numeric($dateValue)) { $saveReturnDateType = Functions::getReturnDateType(); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); - $dateValue = DateValue::funcDateValue($dateValue); + $dateValue = DateValue::evaluate($dateValue); Functions::setReturnDateType($saveReturnDateType); if (!is_numeric($dateValue)) { throw new Exception(Functions::VALUE()); @@ -67,13 +67,18 @@ class Helpers { $saveReturnDateType = Functions::getReturnDateType(); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); - $timeValue = TimeValue::funcTimeValue($timeValue); + $timeValue = TimeValue::evaluate($timeValue); Functions::setReturnDateType($saveReturnDateType); return $timeValue; } - public static function adjustDateByMonths($dateValue = 0, $adjustmentMonths = 0) + /** + * Adjust date by given months. + * + * @param mixed $dateValue + */ + public static function adjustDateByMonths($dateValue = 0, float $adjustmentMonths = 0): DateTime { // Execute function $PHPDateObject = Date::excelToDateTimeObject($dateValue); @@ -194,8 +199,10 @@ class Helpers return (float) Date::PHPToExcel($PHPDateObject); } // RETURNDATE_UNIX_TIMESTAMP + $stamp = Date::PHPToExcel($PHPDateObject); + $stamp = is_bool($stamp) ? ((int) $stamp) : $stamp; - return (int) Date::excelToTimestamp(Date::PHPToExcel($PHPDateObject)); + return (int) Date::excelToTimestamp($stamp); } private static function baseDate(): int @@ -239,9 +246,12 @@ class Helpers if ($number === null) { return 0; } - if (is_numeric($number)) { + if (is_int($number)) { return $number; } + if (is_numeric($number)) { + return (float) $number; + } throw new Exception(Functions::VALUE()); } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Hour.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Hour.php index 98d4570d..84869036 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Hour.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Hour.php @@ -22,7 +22,7 @@ class Hour * * @return int|string Hour */ - public static function funcHour($timeValue) + public static function evaluate($timeValue) { try { $timeValue = Functions::flattenSingleValue($timeValue); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/IsoWeekNum.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/IsoWeekNum.php index 41959d9a..7d2d65dc 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/IsoWeekNum.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/IsoWeekNum.php @@ -20,7 +20,7 @@ class IsoWeekNum * * @return int|string Week Number */ - public static function funcIsoWeekNum($dateValue) + public static function evaluate($dateValue) { if (self::apparentBug($dateValue)) { return 52; @@ -39,6 +39,10 @@ class IsoWeekNum return (int) $PHPDateObject->format('W'); } + /** + * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), + * PHP DateTime object, or a standard date string + */ private static function apparentBug($dateValue): bool { if (Date::getExcelCalendar() !== DATE::CALENDAR_MAC_1904) { diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Minute.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Minute.php index a1747ec9..1a9d5c21 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Minute.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Minute.php @@ -22,7 +22,7 @@ class Minute * * @return int|string Minute */ - public static function funcMinute($timeValue) + public static function evaluate($timeValue) { try { $timeValue = Functions::flattenSingleValue($timeValue); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php index a9fb8ece..092370ba 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php @@ -21,7 +21,7 @@ class Month * * @return int|string Month of the year */ - public static function funcMonth($dateValue) + public static function evaluate($dateValue) { try { $dateValue = Helpers::getDateValue($dateValue); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php index c700c834..5c586913 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php @@ -23,10 +23,11 @@ class NetworkDays * PHP DateTime object, or a standard date string * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string + * @param mixed $dateArgs * * @return int|string Interval between the dates */ - public static function funcNetworkDays($startDate, $endDate, ...$dateArgs) + public static function evaluate($startDate, $endDate, ...$dateArgs) { try { // Retrieve the mandatory start and end date that are referenced in the function definition @@ -55,7 +56,7 @@ class NetworkDays $holidayCountedArray = []; foreach ($holidayArray as $holidayDate) { if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) { - if ((WeekDay::funcWeekDay($holidayDate, 2) < 6) && (!in_array($holidayDate, $holidayCountedArray))) { + if ((WeekDay::evaluate($holidayDate, 2) < 6) && (!in_array($holidayDate, $holidayCountedArray))) { --$partWeekDays; $holidayCountedArray[] = $holidayDate; } @@ -67,7 +68,7 @@ class NetworkDays private static function calcStartDow(float $startDate): int { - $startDow = 6 - (int) WeekDay::funcWeekDay($startDate, 2); + $startDow = 6 - (int) WeekDay::evaluate($startDate, 2); if ($startDow < 0) { $startDow = 5; } @@ -77,7 +78,7 @@ class NetworkDays private static function calcEndDow(float $endDate): int { - $endDow = (int) WeekDay::funcWeekDay($endDate, 2); + $endDow = (int) WeekDay::evaluate($endDate, 2); if ($endDow >= 6) { $endDow = 0; } @@ -95,7 +96,7 @@ class NetworkDays return $partWeekDays; } - private static function applySign(int $result, float $sDate, float $eDate) + private static function applySign(int $result, float $sDate, float $eDate): int { return ($sDate > $eDate) ? -$result : $result; } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Now.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Now.php index 6e6bd171..a0dea86f 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Now.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Now.php @@ -24,7 +24,7 @@ class Now * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function funcNow() + public static function evaluate() { $dti = new DateTimeImmutable(); $dateArray = date_parse($dti->format('c')); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Second.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Second.php index c4749993..c3e15d86 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Second.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Second.php @@ -22,7 +22,7 @@ class Second * * @return int|string Minute */ - public static function funcSecond($timeValue) + public static function evaluate($timeValue) { try { $timeValue = Functions::flattenSingleValue($timeValue); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php index 450f9d50..7f29ba2c 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php @@ -20,14 +20,14 @@ class Time * Excel Function: * TIME(hour,minute,second) * - * @param int $hour A number from 0 (zero) to 32767 representing the hour. + * @param mixed $hour A number from 0 (zero) to 32767 representing the hour. * Any value greater than 23 will be divided by 24 and the remainder * will be treated as the hour value. For example, TIME(27,0,0) = * TIME(3,0,0) = .125 or 3:00 AM. - * @param int $minute A number from 0 to 32767 representing the minute. + * @param mixed $minute A number from 0 to 32767 representing the minute. * Any value greater than 59 will be converted to hours and minutes. * For example, TIME(0,750,0) = TIME(12,30,0) = .520833 or 12:30 PM. - * @param int $second A number from 0 to 32767 representing the second. + * @param mixed $second A number from 0 to 32767 representing the second. * Any value greater than 59 will be converted to hours, minutes, * and seconds. For example, TIME(0,0,2000) = TIME(0,33,22) = .023148 * or 12:33:20 AM @@ -35,7 +35,7 @@ class Time * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function funcTime($hour, $minute, $second) + public static function evaluate($hour, $minute, $second) { try { $hour = self::toIntWithNullBool($hour); @@ -100,6 +100,9 @@ class Time } } + /** + * @param mixed $value expect int + */ private static function toIntWithNullBool($value): int { $value = Functions::flattenSingleValue($value); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php index 2366b1d6..46fa4136 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php @@ -29,12 +29,12 @@ class TimeValue * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function funcTimeValue($timeValue) + public static function evaluate($timeValue) { $timeValue = trim(Functions::flattenSingleValue($timeValue), '"'); $timeValue = str_replace(['/', '.'], '-', $timeValue); - $arraySplit = preg_split('/[\/:\-\s]/', $timeValue); + $arraySplit = preg_split('/[\/:\-\s]/', $timeValue) ?: []; if ((count($arraySplit) == 2 || count($arraySplit) == 3) && $arraySplit[0] > 24) { $arraySplit[0] = ($arraySplit[0] % 24); $timeValue = implode(':', $arraySplit); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Today.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Today.php index 5e459410..545f0efb 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Today.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Today.php @@ -24,7 +24,7 @@ class Today * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function funcToday() + public static function evaluate() { $dti = new DateTimeImmutable(); $dateArray = date_parse($dti->format('c')); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekDay.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekDay.php index ea4fe340..6745557d 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekDay.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekDay.php @@ -19,14 +19,14 @@ class WeekDay * * @param null|float|int|string $dateValue Excel date serial value (float), PHP date timestamp (integer), * PHP DateTime object, or a standard date string - * @param int $style A number that determines the type of return value + * @param mixed $style A number that determines the type of return value * 1 or omitted Numbers 1 (Sunday) through 7 (Saturday). * 2 Numbers 1 (Monday) through 7 (Sunday). * 3 Numbers 0 (Monday) through 6 (Sunday). * * @return int|string Day of the week value */ - public static function funcWeekDay($dateValue, $style = 1) + public static function evaluate($dateValue, $style = 1) { try { $dateValue = Helpers::getDateValue($dateValue); @@ -58,6 +58,9 @@ class WeekDay return $DoW; } + /** + * @param mixed $style expect int + */ private static function validateStyle($style): int { $style = Functions::flattenSingleValue($style); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekNum.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekNum.php index 9b2de4d0..35634e4e 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekNum.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekNum.php @@ -38,7 +38,7 @@ class WeekNum * * @return int|string Week Number */ - public static function funcWeekNum($dateValue, $method = Constants::STARTWEEK_SUNDAY) + public static function evaluate($dateValue, $method = Constants::STARTWEEK_SUNDAY) { $origDateValueNull = empty($dateValue); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php index 09816d33..502cc0d6 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php @@ -24,11 +24,12 @@ class WorkDay * @param int $endDays The number of nonweekend and nonholiday days before or after * startDate. A positive value for days yields a future date; a * negative value yields a past date. + * @param mixed $dateArgs * * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function funcWorkDay($startDate, $endDays, ...$dateArgs) + public static function evaluate($startDate, $endDays, ...$dateArgs) { // Retrieve the mandatory start date and days that are referenced in the function definition try { @@ -65,8 +66,8 @@ class WorkDay { // Adjust the start date if it falls over a weekend - $startDoW = WeekDay::funcWeekDay($startDate, 3); - if (WeekDay::funcWeekDay($startDate, 3) >= 5) { + $startDoW = self::getWeekDay($startDate, 3); + if (self::getWeekDay($startDate, 3) >= 5) { $startDate += 7 - $startDoW; --$endDays; } @@ -77,7 +78,7 @@ class WorkDay while ($endDays > 0) { ++$endDate; // Adjust the calculated end date if it falls over a weekend - $endDow = WeekDay::funcWeekDay($endDate, 3); + $endDow = self::getWeekDay($endDate, 3); if ($endDow >= 5) { $endDate += 7 - $endDow; } @@ -96,7 +97,7 @@ class WorkDay { $holidayCountedArray = $holidayDates = []; foreach ($holidayArray as $holidayDate) { - if (WeekDay::funcWeekDay($holidayDate, 3) < 5) { + if (self::getWeekDay($holidayDate, 3) < 5) { $holidayDates[] = $holidayDate; } } @@ -109,7 +110,7 @@ class WorkDay } } // Adjust the calculated end date if it falls over a weekend - $endDoW = WeekDay::funcWeekDay($endDate, 3); + $endDoW = self::getWeekDay($endDate, 3); if ($endDoW >= 5) { $endDate += 7 - $endDoW; } @@ -127,9 +128,8 @@ class WorkDay { // Adjust the start date if it falls over a weekend - $startDoW = WeekDay::funcWeekDay($startDate, 3); - if (WeekDay::funcWeekDay($startDate, 3) >= 5) { - // @phpstan-ignore-next-line + $startDoW = self::getWeekDay($startDate, 3); + if (self::getWeekDay($startDate, 3) >= 5) { $startDate += -$startDoW + 4; ++$endDays; } @@ -140,7 +140,7 @@ class WorkDay while ($endDays < 0) { --$endDate; // Adjust the calculated end date if it falls over a weekend - $endDow = WeekDay::funcWeekDay($endDate, 3); + $endDow = self::getWeekDay($endDate, 3); if ($endDow >= 5) { $endDate += 4 - $endDow; } @@ -159,7 +159,7 @@ class WorkDay { $holidayCountedArray = $holidayDates = []; foreach ($holidayArray as $holidayDate) { - if (WeekDay::funcWeekDay($holidayDate, 3) < 5) { + if (self::getWeekDay($holidayDate, 3) < 5) { $holidayDates[] = $holidayDate; } } @@ -172,13 +172,19 @@ class WorkDay } } // Adjust the calculated end date if it falls over a weekend - $endDoW = WeekDay::funcWeekDay($endDate, 3); + $endDoW = self::getWeekDay($endDate, 3); if ($endDoW >= 5) { - // @phpstan-ignore-next-line $endDate += -$endDoW + 4; } } return $endDate; } + + private static function getWeekDay(float $date, int $wd): int + { + $result = WeekDay::evaluate($date, $wd); + + return is_string($result) ? -1 : $result; + } } diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Year.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Year.php index 5fcac739..2b7a10c6 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Year.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Year.php @@ -21,7 +21,7 @@ class Year * * @return int|string Year */ - public static function funcYear($dateValue) + public static function evaluate($dateValue) { try { $dateValue = Helpers::getDateValue($dateValue); diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php index a99b1c7f..3d49be47 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php @@ -34,7 +34,7 @@ class YearFrac * * @return float|string fraction of the year, or a string containing an error */ - public static function funcYearFrac($startDate, $endDate, $method = 0) + public static function evaluate($startDate, $endDate, $method = 0) { try { $method = (int) Helpers::validateNumericNull($method); @@ -50,15 +50,15 @@ class YearFrac switch ($method) { case 0: - return Days360::funcDays360($startDate, $endDate) / 360; + return Days360::evaluate($startDate, $endDate) / 360; case 1: return self::method1($startDate, $endDate); case 2: - return DateDif::funcDateDif($startDate, $endDate) / 360; + return DateDif::evaluate($startDate, $endDate) / 360; case 3: - return DateDif::funcDateDif($startDate, $endDate) / 365; + return DateDif::evaluate($startDate, $endDate) / 365; case 4: - return Days360::funcDays360($startDate, $endDate, true) / 360; + return Days360::evaluate($startDate, $endDate, true) / 360; } return Functions::NAN(); @@ -74,7 +74,7 @@ class YearFrac { if (Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE && Date::getExcelCalendar() !== Date::CALENDAR_MAC_1904) { if ($endDate === null && $startDate !== null) { - if (Month::funcMonth($sDate) == 12 && Day::funcDay($sDate) === 31 && $method === 0) { + if (Month::evaluate($sDate) == 12 && Day::evaluate($sDate) === 31 && $method === 0) { $sDate += 2; } else { ++$sDate; @@ -87,14 +87,14 @@ class YearFrac private static function method1(float $startDate, float $endDate): float { - $days = DateDif::funcDateDif($startDate, $endDate); - $startYear = Year::funcYear($startDate); - $endYear = Year::funcYear($endDate); + $days = DateDif::evaluate($startDate, $endDate); + $startYear = (int) Year::evaluate($startDate); + $endYear = (int) Year::evaluate($endDate); $years = $endYear - $startYear + 1; - $startMonth = Month::funcMonth($startDate); - $startDay = Day::funcDay($startDate); - $endMonth = Month::funcMonth($endDate); - $endDay = Day::funcDay($endDate); + $startMonth = (int) Month::evaluate($startDate); + $startDay = (int) Day::evaluate($startDate); + $endMonth = (int) Month::evaluate($endDate); + $endDay = (int) Day::evaluate($endDate); $startMonthDay = 100 * $startMonth + $startDay; $endMonthDay = 100 * $endMonth + $endDay; if ($years == 1) { diff --git a/src/PhpSpreadsheet/Calculation/Financial/Amortization.php b/src/PhpSpreadsheet/Calculation/Financial/Amortization.php index 2ea0f4fe..c10e3304 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Amortization.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Amortization.php @@ -70,7 +70,7 @@ class Amortization return $e->getMessage(); } - $yearFrac = DateTimeExcel\YearFrac::funcYearFrac($purchased, $firstPeriod, $basis); + $yearFrac = DateTimeExcel\YearFrac::evaluate($purchased, $firstPeriod, $basis); if (is_string($yearFrac)) { return $yearFrac; } @@ -160,8 +160,8 @@ class Amortization $fOneRate = $cost * $rate; $fCostDelta = $cost - $salvage; // Note, quirky variation for leap years on the YEARFRAC for this function - $purchasedYear = DateTimeExcel\Year::funcYear($purchased); - $yearFrac = DateTimeExcel\YearFrac::funcYearFrac($purchased, $firstPeriod, $basis); + $purchasedYear = DateTimeExcel\Year::evaluate($purchased); + $yearFrac = DateTimeExcel\YearFrac::evaluate($purchased, $firstPeriod, $basis); if (is_string($yearFrac)) { return $yearFrac; } diff --git a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php index 40df776f..251ae46d 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php +++ b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php @@ -196,10 +196,9 @@ class NonPeriodic return $e->getMessage(); } if ($date0 > $datei) { - /** @phpstan-ignore-next-line */ - $dif = $ordered ? Functions::NAN() : -DateTimeExcel\DateDif::funcDateDif($datei, $date0, 'd'); + $dif = $ordered ? Functions::NAN() : -((int) DateTimeExcel\DateDif::evaluate($datei, $date0, 'd')); } else { - $dif = DateTimeExcel\DateDif::funcDateDif($date0, $datei, 'd'); + $dif = DateTimeExcel\DateDif::evaluate($date0, $datei, 'd'); } if (!is_numeric($dif)) { return $dif; diff --git a/src/PhpSpreadsheet/Calculation/Financial/Coupons.php b/src/PhpSpreadsheet/Calculation/Financial/Coupons.php index b95625cf..7f8f4b7c 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Coupons.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Coupons.php @@ -63,17 +63,17 @@ class Coupons return $e->getMessage(); } - $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis); + $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::evaluate($settlement), $basis); if (is_string($daysPerYear)) { return Functions::VALUE(); } $prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS); if ($basis === FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL) { - return abs(DateTimeExcel\Days::funcDays($prev, $settlement)); + return abs((float) DateTimeExcel\Days::evaluate($prev, $settlement)); } - return DateTimeExcel\YearFrac::funcYearFrac($prev, $settlement, $basis) * $daysPerYear; + return DateTimeExcel\YearFrac::evaluate($prev, $settlement, $basis) * $daysPerYear; } /** @@ -133,7 +133,7 @@ class Coupons case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL: // Actual/actual if ($frequency == FinancialConstants::FREQUENCY_ANNUAL) { - $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis); + $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::evaluate($settlement), $basis); return $daysPerYear / $frequency; } @@ -197,7 +197,7 @@ class Coupons return $e->getMessage(); } - $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis); + $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::evaluate($settlement), $basis); $next = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_NEXT); if ($basis === FinancialConstants::BASIS_DAYS_PER_YEAR_NASD) { @@ -208,7 +208,7 @@ class Coupons } } - return DateTimeExcel\YearFrac::funcYearFrac($settlement, $next, $basis) * $daysPerYear; + return DateTimeExcel\YearFrac::evaluate($settlement, $next, $basis) * $daysPerYear; } /** @@ -316,7 +316,7 @@ class Coupons return $e->getMessage(); } - $yearsBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac( + $yearsBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate( $settlement, $maturity, FinancialConstants::BASIS_DAYS_PER_YEAR_NASD diff --git a/src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php b/src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php index 004b47f3..707423b5 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php @@ -78,12 +78,12 @@ class AccruedInterest return $e->getMessage(); } - $daysBetweenIssueAndSettlement = YearFrac::funcYearFrac($issue, $settlement, $basis); + $daysBetweenIssueAndSettlement = YearFrac::evaluate($issue, $settlement, $basis); if (!is_numeric($daysBetweenIssueAndSettlement)) { // return date error return $daysBetweenIssueAndSettlement; } - $daysBetweenFirstInterestAndSettlement = YearFrac::funcYearFrac($firstInterest, $settlement, $basis); + $daysBetweenFirstInterestAndSettlement = YearFrac::evaluate($firstInterest, $settlement, $basis); if (!is_numeric($daysBetweenFirstInterestAndSettlement)) { // return date error return $daysBetweenFirstInterestAndSettlement; @@ -140,7 +140,7 @@ class AccruedInterest return $e->getMessage(); } - $daysBetweenIssueAndSettlement = YearFrac::funcYearFrac($issue, $settlement, $basis); + $daysBetweenIssueAndSettlement = YearFrac::evaluate($issue, $settlement, $basis); if (!is_numeric($daysBetweenIssueAndSettlement)) { // return date error return $daysBetweenIssueAndSettlement; diff --git a/src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php b/src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php index 158347e7..2c43254c 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php @@ -134,7 +134,7 @@ class Price return $e->getMessage(); } - $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis); + $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); if (!is_numeric($daysBetweenSettlementAndMaturity)) { // return date error return $daysBetweenSettlementAndMaturity; @@ -194,23 +194,23 @@ class Price return $e->getMessage(); } - $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis); + $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::evaluate($settlement), $basis); if (!is_numeric($daysPerYear)) { return $daysPerYear; } - $daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::funcYearFrac($issue, $settlement, $basis); + $daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::evaluate($issue, $settlement, $basis); if (!is_numeric($daysBetweenIssueAndSettlement)) { // return date error return $daysBetweenIssueAndSettlement; } $daysBetweenIssueAndSettlement *= $daysPerYear; - $daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($issue, $maturity, $basis); + $daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::evaluate($issue, $maturity, $basis); if (!is_numeric($daysBetweenIssueAndMaturity)) { // return date error return $daysBetweenIssueAndMaturity; } $daysBetweenIssueAndMaturity *= $daysPerYear; - $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis); + $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); if (!is_numeric($daysBetweenSettlementAndMaturity)) { // return date error return $daysBetweenSettlementAndMaturity; @@ -272,7 +272,7 @@ class Price if ($investment <= 0) { return Functions::NAN(); } - $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis); + $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); if (!is_numeric($daysBetweenSettlementAndMaturity)) { // return date error return $daysBetweenSettlementAndMaturity; diff --git a/src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php b/src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php index 5a32d1d1..3a46b40b 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php @@ -63,7 +63,7 @@ class Rates return Functions::NAN(); } - $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis); + $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); if (!is_numeric($daysBetweenSettlementAndMaturity)) { // return date error return $daysBetweenSettlementAndMaturity; @@ -126,7 +126,7 @@ class Rates return Functions::NAN(); } - $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis); + $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); if (!is_numeric($daysBetweenSettlementAndMaturity)) { // return date error return $daysBetweenSettlementAndMaturity; diff --git a/src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php b/src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php index bdd638fa..416a9c50 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php @@ -57,11 +57,11 @@ class Yields return $e->getMessage(); } - $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis); + $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::evaluate($settlement), $basis); if (!is_numeric($daysPerYear)) { return $daysPerYear; } - $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis); + $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); if (!is_numeric($daysBetweenSettlementAndMaturity)) { // return date error return $daysBetweenSettlementAndMaturity; @@ -122,23 +122,23 @@ class Yields return $e->getMessage(); } - $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis); + $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::evaluate($settlement), $basis); if (!is_numeric($daysPerYear)) { return $daysPerYear; } - $daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::funcYearFrac($issue, $settlement, $basis); + $daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::evaluate($issue, $settlement, $basis); if (!is_numeric($daysBetweenIssueAndSettlement)) { // return date error return $daysBetweenIssueAndSettlement; } $daysBetweenIssueAndSettlement *= $daysPerYear; - $daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($issue, $maturity, $basis); + $daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::evaluate($issue, $maturity, $basis); if (!is_numeric($daysBetweenIssueAndMaturity)) { // return date error return $daysBetweenIssueAndMaturity; } $daysBetweenIssueAndMaturity *= $daysPerYear; - $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis); + $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); if (!is_numeric($daysBetweenSettlementAndMaturity)) { // return date error return $daysBetweenSettlementAndMaturity; diff --git a/src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php b/src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php index 31146c31..2e186d52 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php +++ b/src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php @@ -43,7 +43,7 @@ class TreasuryBill $daysBetweenSettlementAndMaturity = $maturity - $settlement; $daysPerYear = Helpers::daysPerYear( - DateTimeExcel\Year::funcYear($maturity), + DateTimeExcel\Year::evaluate($maturity), FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL ); @@ -88,7 +88,7 @@ class TreasuryBill $daysBetweenSettlementAndMaturity = $maturity - $settlement; $daysPerYear = Helpers::daysPerYear( - DateTimeExcel\Year::funcYear($maturity), + DateTimeExcel\Year::evaluate($maturity), FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL ); @@ -134,7 +134,7 @@ class TreasuryBill $daysBetweenSettlementAndMaturity = $maturity - $settlement; $daysPerYear = Helpers::daysPerYear( - DateTimeExcel\Year::funcYear($maturity), + DateTimeExcel\Year::evaluate($maturity), FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL ); diff --git a/src/PhpSpreadsheet/Calculation/TextData/Format.php b/src/PhpSpreadsheet/Calculation/TextData/Format.php index 7b0e6efa..3b7f0486 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Format.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Format.php @@ -98,7 +98,7 @@ class Format $format = Functions::flattenSingleValue($format); if ((is_string($value)) && (!is_numeric($value)) && Date::isDateTimeFormatCode($format)) { - $value = DateTimeExcel\DateValue::funcDateValue($value); + $value = DateTimeExcel\DateValue::evaluate($value); } return (string) NumberFormat::toFormattedString($value, $format); @@ -129,14 +129,14 @@ class Format Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); if (strpos($value, ':') !== false) { - $timeValue = DateTimeExcel\TimeValue::funcTimeValue($value); + $timeValue = DateTimeExcel\TimeValue::evaluate($value); if ($timeValue !== Functions::VALUE()) { Functions::setReturnDateType($dateSetting); return $timeValue; } } - $dateValue = DateTimeExcel\DateValue::funcDateValue($value); + $dateValue = DateTimeExcel\DateValue::evaluate($value); if ($dateValue !== Functions::VALUE()) { Functions::setReturnDateType($dateSetting); diff --git a/src/PhpSpreadsheet/Shared/Date.php b/src/PhpSpreadsheet/Shared/Date.php index 898dd523..a56ca3df 100644 --- a/src/PhpSpreadsheet/Shared/Date.php +++ b/src/PhpSpreadsheet/Shared/Date.php @@ -437,14 +437,14 @@ class Date return false; } - $dateValueNew = DateTimeExcel\DateValue::funcDateValue($dateValue); + $dateValueNew = DateTimeExcel\DateValue::evaluate($dateValue); if ($dateValueNew === Functions::VALUE()) { return false; } if (strpos($dateValue, ':') !== false) { - $timeValue = DateTimeExcel\TimeValue::funcTimeValue($dateValue); + $timeValue = DateTimeExcel\TimeValue::evaluate($dateValue); if ($timeValue === Functions::VALUE()) { return false; } diff --git a/src/PhpSpreadsheet/Worksheet/AutoFilter.php b/src/PhpSpreadsheet/Worksheet/AutoFilter.php index 1a710e40..394a3896 100644 --- a/src/PhpSpreadsheet/Worksheet/AutoFilter.php +++ b/src/PhpSpreadsheet/Worksheet/AutoFilter.php @@ -472,7 +472,7 @@ class AutoFilter $val = $maxVal = null; $ruleValues = []; - $baseDate = DateTimeExcel\Now::funcNow(); + $baseDate = DateTimeExcel\Now::evaluate(); // Calculate start/end dates for the required date range based on current date switch ($dynamicRuleType) { case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTWEEK: diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php index d790777b..28988ded 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php @@ -29,7 +29,7 @@ class DateTest extends AllSetupTeardown { self::setUnixReturn(); - $result = Datefunc::funcDate(2012, 1, 31); // 32-bit safe + $result = Datefunc::evaluate(2012, 1, 31); // 32-bit safe self::assertEquals(1327968000, $result); } @@ -37,7 +37,7 @@ class DateTest extends AllSetupTeardown { self::setObjectReturn(); - $result = Datefunc::funcDate(2012, 1, 31); + $result = Datefunc::evaluate(2012, 1, 31); // Must return an object... self::assertIsObject($result); // ... of the correct type @@ -50,10 +50,10 @@ class DateTest extends AllSetupTeardown { self::setMac1904(); - $result = Datefunc::funcDate(1918, 11, 11); + $result = Datefunc::evaluate(1918, 11, 11); self::assertEquals($result, 5428); - $result = Datefunc::funcDate(1901, 1, 31); + $result = Datefunc::evaluate(1901, 1, 31); self::assertEquals($result, '#NUM!'); } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php index 2d422e0a..13e56671 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php @@ -26,7 +26,7 @@ class DateValueTest extends AllSetupTeardown if (is_string($expectedResult)) { $replYMD = str_replace('Y', date('Y'), $expectedResult); if ($replYMD !== $expectedResult) { - $expectedResult = DateValue::funcDateValue($replYMD); + $expectedResult = DateValue::evaluate($replYMD); } } $this->sheet->getCell("A$row")->setValue("=DATEVALUE($dateValue)"); @@ -46,7 +46,7 @@ class DateValueTest extends AllSetupTeardown { self::setUnixReturn(); - $result = DateValue::funcDateValue('2012-1-31'); + $result = DateValue::evaluate('2012-1-31'); self::assertEquals(1327968000, $result); self::assertEqualsWithDelta(1327968000, $result, 1E-8); } @@ -55,7 +55,7 @@ class DateValueTest extends AllSetupTeardown { self::setObjectReturn(); - $result = DateValue::funcDateValue('2012-1-31'); + $result = DateValue::evaluate('2012-1-31'); // Must return an object... self::assertIsObject($result); // ... of the correct type @@ -67,9 +67,9 @@ class DateValueTest extends AllSetupTeardown public function testDATEVALUEwith1904Calendar(): void { self::setMac1904(); - self::assertEquals(5428, DateValue::funcDateValue('1918-11-11')); - self::assertEquals(0, DateValue::funcDateValue('1904-01-01')); - self::assertEquals('#VALUE!', DateValue::funcDateValue('1903-12-31')); - self::assertEquals('#VALUE!', DateValue::funcDateValue('1900-02-29')); + self::assertEquals(5428, DateValue::evaluate('1918-11-11')); + self::assertEquals(0, DateValue::evaluate('1904-01-01')); + self::assertEquals('#VALUE!', DateValue::evaluate('1903-12-31')); + self::assertEquals('#VALUE!', DateValue::evaluate('1900-02-29')); } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php index 8c65622a..b88ba391 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php @@ -33,13 +33,13 @@ class DaysTest extends AllSetupTeardown { $obj1 = new DateTime('2000-3-31'); $obj2 = new DateTimeImmutable('2000-2-29'); - self::assertSame(31, Days::funcDays($obj1, $obj2)); + self::assertSame(31, Days::evaluate($obj1, $obj2)); } public function testNonDateObject(): void { $obj1 = new Exception(); $obj2 = new DateTimeImmutable('2000-2-29'); - self::assertSame('#VALUE!', Days::funcDays($obj1, $obj2)); + self::assertSame('#VALUE!', Days::evaluate($obj1, $obj2)); } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php index efb34d0d..8943911b 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php @@ -29,7 +29,7 @@ class EDateTest extends AllSetupTeardown { self::setUnixReturn(); - $result = EDate::funcEDate('2012-1-26', -1); + $result = EDate::evaluate('2012-1-26', -1); self::assertEquals(1324857600, $result); self::assertEqualsWithDelta(1324857600, $result, 1E-8); } @@ -38,7 +38,7 @@ class EDateTest extends AllSetupTeardown { self::setObjectReturn(); - $result = EDate::funcEDate('2012-1-26', -1); + $result = EDate::evaluate('2012-1-26', -1); // Must return an object... self::assertIsObject($result); // ... of the correct type diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php index 6db76f58..eabaf494 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php @@ -29,7 +29,7 @@ class EoMonthTest extends AllSetupTeardown { self::setUnixReturn(); - $result = EoMonth::funcEomonth('2012-1-26', -1); + $result = EoMonth::evaluate('2012-1-26', -1); self::assertEquals(1325289600, $result); } @@ -37,7 +37,7 @@ class EoMonthTest extends AllSetupTeardown { self::setObjectReturn(); - $result = EoMonth::funcEomonth('2012-1-26', -1); + $result = EoMonth::evaluate('2012-1-26', -1); // Must return an object... self::assertIsObject($result); // ... of the correct type diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php index d6910024..053385e7 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php @@ -31,7 +31,7 @@ class TimeTest extends AllSetupTeardown { self::setUnixReturn(); - $result = Time::funcTime(7, 30, 20); + $result = Time::evaluate(7, 30, 20); self::assertEqualsWithDelta(27020, $result, 1E-8); } @@ -39,7 +39,7 @@ class TimeTest extends AllSetupTeardown { self::setObjectReturn(); - $result = Time::funcTime(7, 30, 20); + $result = Time::evaluate(7, 30, 20); // Must return an object... self::assertIsObject($result); // ... of the correct type @@ -51,13 +51,13 @@ class TimeTest extends AllSetupTeardown public function testTIME1904(): void { self::setMac1904(); - $result = Time::funcTime(0, 0, 0); + $result = Time::evaluate(0, 0, 0); self::assertEquals(0, $result); } public function testTIME1900(): void { - $result = Time::funcTime(0, 0, 0); + $result = Time::evaluate(0, 0, 0); self::assertEquals(0, $result); } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php index ac4d3dbd..1eea77cb 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php @@ -31,7 +31,7 @@ class TimeValueTest extends AllSetupTeardown { self::setUnixReturn(); - $result = TimeValue::funcTimeValue('7:30:20'); + $result = TimeValue::evaluate('7:30:20'); self::assertEquals(23420, $result); self::assertEqualsWithDelta(23420, $result, 1E-8); } @@ -40,7 +40,7 @@ class TimeValueTest extends AllSetupTeardown { self::setObjectReturn(); - $result = TimeValue::funcTimeValue('7:30:20'); + $result = TimeValue::evaluate('7:30:20'); // Must return an object... self::assertIsObject($result); // ... of the correct type diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.php index c95ce9cc..30898988 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.php @@ -28,8 +28,8 @@ class WeekDayTest extends AllSetupTeardown public function testWEEKDAYwith1904Calendar(): void { self::setMac1904(); - self::assertEquals(7, WeekDay::funcWeekDay('1904-01-02')); - self::assertEquals(6, WeekDay::funcWeekDay('1904-01-01')); - self::assertEquals(6, WeekDay::funcWeekDay(null)); + self::assertEquals(7, WeekDay::evaluate('1904-01-02')); + self::assertEquals(6, WeekDay::evaluate('1904-01-01')); + self::assertEquals(6, WeekDay::evaluate(null)); } }