Renaming the last of the DateTime implementation methods

This commit is contained in:
MarkBaker 2021-05-12 16:12:11 +02:00 committed by Mark Baker
parent f7a07747fd
commit 765d4586ae
9 changed files with 35 additions and 35 deletions

View File

@ -758,12 +758,12 @@ class Calculation
], ],
'DATE' => [ 'DATE' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\Datefunc::class, 'fromYMD'], 'functionCall' => [DateTimeExcel\Date::class, 'fromYMD'],
'argumentCount' => '3', 'argumentCount' => '3',
], ],
'DATEDIF' => [ 'DATEDIF' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\DateDif::class, 'interval'], 'functionCall' => [DateTimeExcel\Difference::class, 'interval'],
'argumentCount' => '2,3', 'argumentCount' => '2,3',
], ],
'DATEVALUE' => [ 'DATEVALUE' => [
@ -1764,7 +1764,7 @@ class Calculation
], ],
'NETWORKDAYS' => [ 'NETWORKDAYS' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\NetworkDays::class, 'evaluate'], 'functionCall' => [DateTimeExcel\NetworkDays::class, 'count'],
'argumentCount' => '2-3', 'argumentCount' => '2-3',
], ],
'NETWORKDAYS.INTL' => [ 'NETWORKDAYS.INTL' => [
@ -2594,7 +2594,7 @@ class Calculation
], ],
'WORKDAY' => [ 'WORKDAY' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\WorkDay::class, 'evaluate'], 'functionCall' => [DateTimeExcel\WorkDay::class, 'date'],
'argumentCount' => '2-3', 'argumentCount' => '2-3',
], ],
'WORKDAY.INTL' => [ 'WORKDAY.INTL' => [

View File

@ -115,8 +115,8 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\Datefunc::fromYMD() * @See DateTimeExcel\Date::fromYMD()
* Use the fromYMD method in the DateTimeExcel\Datefunc class instead * Use the fromYMD method in the DateTimeExcel\Date 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.
* A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted, * A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted,
@ -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::fromYMD($year, $month, $day); return DateTimeExcel\Date::fromYMD($year, $month, $day);
} }
/** /**
@ -271,8 +271,8 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\DateDif::interval() * @See DateTimeExcel\Difference::interval()
* Use the interval method in the DateTimeExcel\DateDif class instead * Use the interval method in the DateTimeExcel\Difference class instead
* *
* @param mixed $startDate Excel date serial value, PHP date/time stamp, PHP DateTime object * @param mixed $startDate Excel date serial value, PHP date/time stamp, PHP DateTime object
* or a standard date string * or a standard date string
@ -284,7 +284,7 @@ class DateTime
*/ */
public static function DATEDIF($startDate = 0, $endDate = 0, $unit = 'D') public static function DATEDIF($startDate = 0, $endDate = 0, $unit = 'D')
{ {
return DateTimeExcel\DateDif::interval($startDate, $endDate, $unit); return DateTimeExcel\Difference::interval($startDate, $endDate, $unit);
} }
/** /**
@ -400,8 +400,8 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\NetworkDays::evaluate() * @See DateTimeExcel\NetworkDays::count()
* Use the evaluate method in the DateTimeExcel\NetworkDays class instead * Use the count method in the DateTimeExcel\NetworkDays class instead
* *
* @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string * PHP DateTime object, or a standard date string
@ -413,7 +413,7 @@ class DateTime
*/ */
public static function NETWORKDAYS($startDate, $endDate, ...$dateArgs) public static function NETWORKDAYS($startDate, $endDate, ...$dateArgs)
{ {
return DateTimeExcel\NetworkDays::evaluate($startDate, $endDate, ...$dateArgs); return DateTimeExcel\NetworkDays::count($startDate, $endDate, ...$dateArgs);
} }
/** /**
@ -429,8 +429,8 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\WorkDay::evaluate() * @See DateTimeExcel\WorkDay::date()
* Use the evaluate method in the DateTimeExcel\WorkDay class instead * Use the date method in the DateTimeExcel\WorkDay class instead
* *
* @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string * PHP DateTime object, or a standard date string
@ -444,7 +444,7 @@ class DateTime
*/ */
public static function WORKDAY($startDate, $endDays, ...$dateArgs) public static function WORKDAY($startDate, $endDays, ...$dateArgs)
{ {
return DateTimeExcel\WorkDay::evaluate($startDate, $endDays, ...$dateArgs); return DateTimeExcel\WorkDay::date($startDate, $endDays, ...$dateArgs);
} }
/** /**

View File

@ -4,10 +4,10 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use Exception; use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
class Datefunc class Date
{ {
/** /**
* DATE. * DATE.
@ -60,7 +60,7 @@ class Datefunc
*/ */
public static function fromYMD($year, $month, $day) public static function fromYMD($year, $month, $day)
{ {
$baseYear = Date::getExcelCalendar(); $baseYear = SharedDateHelper::getExcelCalendar();
try { try {
$year = self::getYear($year, $baseYear); $year = self::getYear($year, $baseYear);
@ -72,7 +72,7 @@ class Datefunc
} }
// Execute function // Execute function
$excelDateValue = Date::formattedPHPToExcel($year, $month, $day); $excelDateValue = SharedDateHelper::formattedPHPToExcel($year, $month, $day);
return Helpers::returnIn3FormatsFloat($excelDateValue); return Helpers::returnIn3FormatsFloat($excelDateValue);
} }
@ -115,7 +115,7 @@ class Datefunc
$month = Functions::flattenSingleValue($month); $month = Functions::flattenSingleValue($month);
if (($month !== null) && (!is_numeric($month))) { if (($month !== null) && (!is_numeric($month))) {
$month = Date::monthStringToNumber($month); $month = SharedDateHelper::monthStringToNumber($month);
} }
$month = ($month !== null) ? StringHelper::testStringAsNumeric((string) $month) : 0; $month = ($month !== null) ? StringHelper::testStringAsNumeric((string) $month) : 0;
@ -136,7 +136,7 @@ class Datefunc
$day = Functions::flattenSingleValue($day); $day = Functions::flattenSingleValue($day);
if (($day !== null) && (!is_numeric($day))) { if (($day !== null) && (!is_numeric($day))) {
$day = Date::dayStringToNumber($day); $day = SharedDateHelper::dayStringToNumber($day);
} }
$day = ($day !== null) ? StringHelper::testStringAsNumeric((string) $day) : 0; $day = ($day !== null) ? StringHelper::testStringAsNumeric((string) $day) : 0;

View File

@ -8,7 +8,7 @@ use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\Date;
class DateDif class Difference
{ {
/** /**
* DATEDIF. * DATEDIF.

View File

@ -27,7 +27,7 @@ class NetworkDays
* *
* @return int|string Interval between the dates * @return int|string Interval between the dates
*/ */
public static function evaluate($startDate, $endDate, ...$dateArgs) public static function count($startDate, $endDate, ...$dateArgs)
{ {
try { try {
// Retrieve the mandatory start and end date that are referenced in the function definition // Retrieve the mandatory start and end date that are referenced in the function definition

View File

@ -29,7 +29,7 @@ class WorkDay
* @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($startDate, $endDays, ...$dateArgs) public static function date($startDate, $endDays, ...$dateArgs)
{ {
// Retrieve the mandatory start date and days that are referenced in the function definition // Retrieve the mandatory start date and days that are referenced in the function definition
try { try {

View File

@ -54,9 +54,9 @@ class YearFrac
case 1: case 1:
return self::method1($startDate, $endDate); return self::method1($startDate, $endDate);
case 2: case 2:
return DateDif::interval($startDate, $endDate) / 360; return Difference::interval($startDate, $endDate) / 360;
case 3: case 3:
return DateDif::interval($startDate, $endDate) / 365; return Difference::interval($startDate, $endDate) / 365;
case 4: case 4:
return Days360::between($startDate, $endDate, true) / 360; return Days360::between($startDate, $endDate, true) / 360;
} }
@ -87,7 +87,7 @@ class YearFrac
private static function method1(float $startDate, float $endDate): float private static function method1(float $startDate, float $endDate): float
{ {
$days = DateDif::interval($startDate, $endDate); $days = Difference::interval($startDate, $endDate);
$startYear = (int) DateParts::year($startDate); $startYear = (int) DateParts::year($startDate);
$endYear = (int) DateParts::year($endDate); $endYear = (int) DateParts::year($endDate);
$years = $endYear - $startYear + 1; $years = $endYear - $startYear + 1;

View File

@ -196,9 +196,9 @@ class NonPeriodic
return $e->getMessage(); return $e->getMessage();
} }
if ($date0 > $datei) { if ($date0 > $datei) {
$dif = $ordered ? Functions::NAN() : -((int) DateTimeExcel\DateDif::interval($datei, $date0, 'd')); $dif = $ordered ? Functions::NAN() : -((int) DateTimeExcel\Difference::interval($datei, $date0, 'd'));
} else { } else {
$dif = DateTimeExcel\DateDif::interval($date0, $datei, 'd'); $dif = DateTimeExcel\Difference::interval($date0, $datei, 'd');
} }
if (!is_numeric($dif)) { if (!is_numeric($dif)) {
return $dif; return $dif;

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Datefunc; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Date;
class DateTest extends AllSetupTeardown class DateTest extends AllSetupTeardown
{ {
@ -29,7 +29,7 @@ class DateTest extends AllSetupTeardown
{ {
self::setUnixReturn(); self::setUnixReturn();
$result = Datefunc::fromYMD(2012, 1, 31); // 32-bit safe $result = Date::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::fromYMD(2012, 1, 31); $result = Date::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::fromYMD(1918, 11, 11); $result = Date::fromYMD(1918, 11, 11);
self::assertEquals($result, 5428); self::assertEquals($result, 5428);
$result = Datefunc::fromYMD(1901, 1, 31); $result = Date::fromYMD(1901, 1, 31);
self::assertEquals($result, '#NUM!'); self::assertEquals($result, '#NUM!');
} }
} }