Some method renaming

This commit is contained in:
MarkBaker 2021-05-12 14:32:39 +02:00 committed by Mark Baker
parent 97472ae383
commit aa3269a863
13 changed files with 42 additions and 42 deletions

View File

@ -758,7 +758,7 @@ class Calculation
], ],
'DATE' => [ 'DATE' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\Datefunc::class, 'evaluate'], 'functionCall' => [DateTimeExcel\Datefunc::class, 'fromYMD'],
'argumentCount' => '3', 'argumentCount' => '3',
], ],
'DATEDIF' => [ 'DATEDIF' => [
@ -768,7 +768,7 @@ class Calculation
], ],
'DATEVALUE' => [ 'DATEVALUE' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\DateValue::class, 'evaluate'], 'functionCall' => [DateTimeExcel\DateValue::class, 'fromString'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'DAVERAGE' => [ 'DAVERAGE' => [
@ -2424,12 +2424,12 @@ class Calculation
], ],
'TIME' => [ 'TIME' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\Time::class, 'evaluate'], 'functionCall' => [DateTimeExcel\Time::class, 'fromHMS'],
'argumentCount' => '3', 'argumentCount' => '3',
], ],
'TIMEVALUE' => [ 'TIMEVALUE' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\TimeValue::class, 'evaluate'], 'functionCall' => [DateTimeExcel\TimeValue::class, 'fromString'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'TINV' => [ 'TINV' => [

View File

@ -115,7 +115,7 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\Datefunc::evaluate() * @See DateTimeExcel\Datefunc::fromYMD()
* Use the evaluate method in the DateTimeExcel\Datefunc class instead * 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. * PhpSpreadsheet is a lot more forgiving than MS Excel when passing non numeric values to this function.
@ -158,7 +158,7 @@ class DateTime
*/ */
public static function DATE($year = 0, $month = 1, $day = 1) public static function DATE($year = 0, $month = 1, $day = 1)
{ {
return DateTimeExcel\Datefunc::evaluate($year, $month, $day); return DateTimeExcel\Datefunc::fromYMD($year, $month, $day);
} }
/** /**
@ -174,7 +174,7 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\Time::evaluate() * @See DateTimeExcel\Time::fromHMS()
* Use the evaluate method in the DateTimeExcel\Time class instead * Use the evaluate method in the DateTimeExcel\Time class instead
* *
* @param int $hour A number from 0 (zero) to 32767 representing the hour. * @param int $hour A number from 0 (zero) to 32767 representing the hour.
@ -194,7 +194,7 @@ class DateTime
*/ */
public static function TIME($hour = 0, $minute = 0, $second = 0) public static function TIME($hour = 0, $minute = 0, $second = 0)
{ {
return DateTimeExcel\Time::evaluate($hour, $minute, $second); return DateTimeExcel\Time::fromHMS($hour, $minute, $second);
} }
/** /**
@ -212,8 +212,8 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\DateValue::evaluate() * @See DateTimeExcel\DateValue::fromString()
* Use the evaluate method in the DateTimeExcel\DateValue class instead * Use the fromString method in the DateTimeExcel\DateValue class instead
* *
* @param string $dateValue Text that represents a date in a Microsoft Excel date format. * @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 * For example, "1/30/2008" or "30-Jan-2008" are text strings within
@ -229,7 +229,7 @@ class DateTime
*/ */
public static function DATEVALUE($dateValue) public static function DATEVALUE($dateValue)
{ {
return DateTimeExcel\DateValue::evaluate($dateValue); return DateTimeExcel\DateValue::fromString($dateValue);
} }
/** /**
@ -247,8 +247,8 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\TimeValue::evaluate() * @See DateTimeExcel\TimeValue::fromString()
* Use the evaluate method in the DateTimeExcel\TimeValue class instead * Use the fromString method in the DateTimeExcel\TimeValue class instead
* *
* @param string $timeValue A text string that represents a time in any one of the Microsoft * @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 * Excel time formats; for example, "6:45 PM" and "18:45" text strings
@ -260,7 +260,7 @@ class DateTime
*/ */
public static function TIMEVALUE($timeValue) public static function TIMEVALUE($timeValue)
{ {
return DateTimeExcel\TimeValue::evaluate($timeValue); return DateTimeExcel\TimeValue::fromString($timeValue);
} }
/** /**

View File

@ -33,7 +33,7 @@ class DateValue
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * @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 * depending on the value of the ReturnDateType flag
*/ */
public static function evaluate($dateValue) public static function fromString($dateValue)
{ {
$dti = new DateTimeImmutable(); $dti = new DateTimeImmutable();
$baseYear = Date::getExcelCalendar(); $baseYear = Date::getExcelCalendar();

View File

@ -58,7 +58,7 @@ class Datefunc
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * @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 * depending on the value of the ReturnDateType flag
*/ */
public static function evaluate($year, $month, $day) public static function fromYMD($year, $month, $day)
{ {
$baseYear = Date::getExcelCalendar(); $baseYear = Date::getExcelCalendar();

View File

@ -43,7 +43,7 @@ class Helpers
if (!is_numeric($dateValue)) { if (!is_numeric($dateValue)) {
$saveReturnDateType = Functions::getReturnDateType(); $saveReturnDateType = Functions::getReturnDateType();
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
$dateValue = DateValue::evaluate($dateValue); $dateValue = DateValue::fromString($dateValue);
Functions::setReturnDateType($saveReturnDateType); Functions::setReturnDateType($saveReturnDateType);
if (!is_numeric($dateValue)) { if (!is_numeric($dateValue)) {
throw new Exception(Functions::VALUE()); throw new Exception(Functions::VALUE());
@ -67,7 +67,7 @@ class Helpers
{ {
$saveReturnDateType = Functions::getReturnDateType(); $saveReturnDateType = Functions::getReturnDateType();
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
$timeValue = TimeValue::evaluate($timeValue); $timeValue = TimeValue::fromString($timeValue);
Functions::setReturnDateType($saveReturnDateType); Functions::setReturnDateType($saveReturnDateType);
return $timeValue; return $timeValue;

View File

@ -35,7 +35,7 @@ class Time
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * @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 * depending on the value of the ReturnDateType flag
*/ */
public static function evaluate($hour, $minute, $second) public static function fromHMS($hour, $minute, $second)
{ {
try { try {
$hour = self::toIntWithNullBool($hour); $hour = self::toIntWithNullBool($hour);

View File

@ -29,7 +29,7 @@ class TimeValue
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * @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 * depending on the value of the ReturnDateType flag
*/ */
public static function evaluate($timeValue) public static function fromString($timeValue)
{ {
$timeValue = trim(Functions::flattenSingleValue($timeValue), '"'); $timeValue = trim(Functions::flattenSingleValue($timeValue), '"');
$timeValue = str_replace(['/', '.'], '-', $timeValue); $timeValue = str_replace(['/', '.'], '-', $timeValue);

View File

@ -98,7 +98,7 @@ class Format
$format = Functions::flattenSingleValue($format); $format = Functions::flattenSingleValue($format);
if ((is_string($value)) && (!is_numeric($value)) && Date::isDateTimeFormatCode($format)) { if ((is_string($value)) && (!is_numeric($value)) && Date::isDateTimeFormatCode($format)) {
$value = DateTimeExcel\DateValue::evaluate($value); $value = DateTimeExcel\DateValue::fromString($value);
} }
return (string) NumberFormat::toFormattedString($value, $format); return (string) NumberFormat::toFormattedString($value, $format);
@ -129,14 +129,14 @@ class Format
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
if (strpos($value, ':') !== false) { if (strpos($value, ':') !== false) {
$timeValue = DateTimeExcel\TimeValue::evaluate($value); $timeValue = DateTimeExcel\TimeValue::fromString($value);
if ($timeValue !== Functions::VALUE()) { if ($timeValue !== Functions::VALUE()) {
Functions::setReturnDateType($dateSetting); Functions::setReturnDateType($dateSetting);
return $timeValue; return $timeValue;
} }
} }
$dateValue = DateTimeExcel\DateValue::evaluate($value); $dateValue = DateTimeExcel\DateValue::fromString($value);
if ($dateValue !== Functions::VALUE()) { if ($dateValue !== Functions::VALUE()) {
Functions::setReturnDateType($dateSetting); Functions::setReturnDateType($dateSetting);

View File

@ -437,14 +437,14 @@ class Date
return false; return false;
} }
$dateValueNew = DateTimeExcel\DateValue::evaluate($dateValue); $dateValueNew = DateTimeExcel\DateValue::fromString($dateValue);
if ($dateValueNew === Functions::VALUE()) { if ($dateValueNew === Functions::VALUE()) {
return false; return false;
} }
if (strpos($dateValue, ':') !== false) { if (strpos($dateValue, ':') !== false) {
$timeValue = DateTimeExcel\TimeValue::evaluate($dateValue); $timeValue = DateTimeExcel\TimeValue::fromString($dateValue);
if ($timeValue === Functions::VALUE()) { if ($timeValue === Functions::VALUE()) {
return false; return false;
} }

View File

@ -29,7 +29,7 @@ class DateTest extends AllSetupTeardown
{ {
self::setUnixReturn(); self::setUnixReturn();
$result = Datefunc::evaluate(2012, 1, 31); // 32-bit safe $result = Datefunc::fromYMD(2012, 1, 31); // 32-bit safe
self::assertEquals(1327968000, $result); self::assertEquals(1327968000, $result);
} }
@ -37,7 +37,7 @@ class DateTest extends AllSetupTeardown
{ {
self::setObjectReturn(); self::setObjectReturn();
$result = Datefunc::evaluate(2012, 1, 31); $result = Datefunc::fromYMD(2012, 1, 31);
// Must return an object... // Must return an object...
self::assertIsObject($result); self::assertIsObject($result);
// ... of the correct type // ... of the correct type
@ -50,10 +50,10 @@ class DateTest extends AllSetupTeardown
{ {
self::setMac1904(); self::setMac1904();
$result = Datefunc::evaluate(1918, 11, 11); $result = Datefunc::fromYMD(1918, 11, 11);
self::assertEquals($result, 5428); self::assertEquals($result, 5428);
$result = Datefunc::evaluate(1901, 1, 31); $result = Datefunc::fromYMD(1901, 1, 31);
self::assertEquals($result, '#NUM!'); self::assertEquals($result, '#NUM!');
} }
} }

View File

@ -26,7 +26,7 @@ class DateValueTest extends AllSetupTeardown
if (is_string($expectedResult)) { if (is_string($expectedResult)) {
$replYMD = str_replace('Y', date('Y'), $expectedResult); $replYMD = str_replace('Y', date('Y'), $expectedResult);
if ($replYMD !== $expectedResult) { if ($replYMD !== $expectedResult) {
$expectedResult = DateValue::evaluate($replYMD); $expectedResult = DateValue::fromString($replYMD);
} }
} }
$this->sheet->getCell("A$row")->setValue("=DATEVALUE($dateValue)"); $this->sheet->getCell("A$row")->setValue("=DATEVALUE($dateValue)");
@ -46,7 +46,7 @@ class DateValueTest extends AllSetupTeardown
{ {
self::setUnixReturn(); self::setUnixReturn();
$result = DateValue::evaluate('2012-1-31'); $result = DateValue::fromString('2012-1-31');
self::assertEquals(1327968000, $result); self::assertEquals(1327968000, $result);
self::assertEqualsWithDelta(1327968000, $result, 1E-8); self::assertEqualsWithDelta(1327968000, $result, 1E-8);
} }
@ -55,7 +55,7 @@ class DateValueTest extends AllSetupTeardown
{ {
self::setObjectReturn(); self::setObjectReturn();
$result = DateValue::evaluate('2012-1-31'); $result = DateValue::fromString('2012-1-31');
// Must return an object... // Must return an object...
self::assertIsObject($result); self::assertIsObject($result);
// ... of the correct type // ... of the correct type
@ -67,9 +67,9 @@ class DateValueTest extends AllSetupTeardown
public function testDATEVALUEwith1904Calendar(): void public function testDATEVALUEwith1904Calendar(): void
{ {
self::setMac1904(); self::setMac1904();
self::assertEquals(5428, DateValue::evaluate('1918-11-11')); self::assertEquals(5428, DateValue::fromString('1918-11-11'));
self::assertEquals(0, DateValue::evaluate('1904-01-01')); self::assertEquals(0, DateValue::fromString('1904-01-01'));
self::assertEquals('#VALUE!', DateValue::evaluate('1903-12-31')); self::assertEquals('#VALUE!', DateValue::fromString('1903-12-31'));
self::assertEquals('#VALUE!', DateValue::evaluate('1900-02-29')); self::assertEquals('#VALUE!', DateValue::fromString('1900-02-29'));
} }
} }

View File

@ -31,7 +31,7 @@ class TimeTest extends AllSetupTeardown
{ {
self::setUnixReturn(); self::setUnixReturn();
$result = Time::evaluate(7, 30, 20); $result = Time::fromHMS(7, 30, 20);
self::assertEqualsWithDelta(27020, $result, 1E-8); self::assertEqualsWithDelta(27020, $result, 1E-8);
} }
@ -39,7 +39,7 @@ class TimeTest extends AllSetupTeardown
{ {
self::setObjectReturn(); self::setObjectReturn();
$result = Time::evaluate(7, 30, 20); $result = Time::fromHMS(7, 30, 20);
// Must return an object... // Must return an object...
self::assertIsObject($result); self::assertIsObject($result);
// ... of the correct type // ... of the correct type
@ -51,13 +51,13 @@ class TimeTest extends AllSetupTeardown
public function testTIME1904(): void public function testTIME1904(): void
{ {
self::setMac1904(); self::setMac1904();
$result = Time::evaluate(0, 0, 0); $result = Time::fromHMS(0, 0, 0);
self::assertEquals(0, $result); self::assertEquals(0, $result);
} }
public function testTIME1900(): void public function testTIME1900(): void
{ {
$result = Time::evaluate(0, 0, 0); $result = Time::fromHMS(0, 0, 0);
self::assertEquals(0, $result); self::assertEquals(0, $result);
} }
} }

View File

@ -31,7 +31,7 @@ class TimeValueTest extends AllSetupTeardown
{ {
self::setUnixReturn(); self::setUnixReturn();
$result = TimeValue::evaluate('7:30:20'); $result = TimeValue::fromString('7:30:20');
self::assertEquals(23420, $result); self::assertEquals(23420, $result);
self::assertEqualsWithDelta(23420, $result, 1E-8); self::assertEqualsWithDelta(23420, $result, 1E-8);
} }
@ -40,7 +40,7 @@ class TimeValueTest extends AllSetupTeardown
{ {
self::setObjectReturn(); self::setObjectReturn();
$result = TimeValue::evaluate('7:30:20'); $result = TimeValue::fromString('7:30:20');
// Must return an object... // Must return an object...
self::assertIsObject($result); self::assertIsObject($result);
// ... of the correct type // ... of the correct type