More method renaming

This commit is contained in:
MarkBaker 2021-05-12 15:22:46 +02:00 committed by Mark Baker
parent aa3269a863
commit f7a07747fd
18 changed files with 103 additions and 112 deletions

View File

@ -763,7 +763,7 @@ class Calculation
], ],
'DATEDIF' => [ 'DATEDIF' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\DateDif::class, 'evaluate'], 'functionCall' => [DateTimeExcel\DateDif::class, 'interval'],
'argumentCount' => '2,3', 'argumentCount' => '2,3',
], ],
'DATEVALUE' => [ 'DATEVALUE' => [
@ -783,12 +783,12 @@ class Calculation
], ],
'DAYS' => [ 'DAYS' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\Days::class, 'evaluate'], 'functionCall' => [DateTimeExcel\Days::class, 'between'],
'argumentCount' => '2', 'argumentCount' => '2',
], ],
'DAYS360' => [ 'DAYS360' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\Days360::class, 'evaluate'], 'functionCall' => [DateTimeExcel\Days360::class, 'between'],
'argumentCount' => '2,3', 'argumentCount' => '2,3',
], ],
'DB' => [ 'DB' => [
@ -923,7 +923,7 @@ class Calculation
], ],
'EDATE' => [ 'EDATE' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\EDate::class, 'evaluate'], 'functionCall' => [DateTimeExcel\Month::class, 'adjust'],
'argumentCount' => '2', 'argumentCount' => '2',
], ],
'EFFECT' => [ 'EFFECT' => [
@ -938,7 +938,7 @@ class Calculation
], ],
'EOMONTH' => [ 'EOMONTH' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\EoMonth::class, 'evaluate'], 'functionCall' => [DateTimeExcel\Month::class, 'lastDay'],
'argumentCount' => '2', 'argumentCount' => '2',
], ],
'ERF' => [ 'ERF' => [
@ -2634,7 +2634,7 @@ class Calculation
], ],
'YEARFRAC' => [ 'YEARFRAC' => [
'category' => Category::CATEGORY_DATE_AND_TIME, 'category' => Category::CATEGORY_DATE_AND_TIME,
'functionCall' => [DateTimeExcel\YearFrac::class, 'evaluate'], 'functionCall' => [DateTimeExcel\YearFrac::class, 'fraction'],
'argumentCount' => '2,3', 'argumentCount' => '2,3',
], ],
'YIELD' => [ 'YIELD' => [

View File

@ -116,7 +116,7 @@ class DateTime
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\Datefunc::fromYMD() * @See DateTimeExcel\Datefunc::fromYMD()
* Use the evaluate method in the DateTimeExcel\Datefunc class instead * Use the fromYMD 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.
* 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,
@ -175,7 +175,7 @@ class DateTime
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\Time::fromHMS() * @See DateTimeExcel\Time::fromHMS()
* Use the evaluate method in the DateTimeExcel\Time class instead * Use the fromHMS 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.
* Any value greater than 23 will be divided by 24 and the remainder * Any value greater than 23 will be divided by 24 and the remainder
@ -271,8 +271,8 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\DateDif::evaluate() * @See DateTimeExcel\DateDif::interval()
* Use the evaluate method in the DateTimeExcel\DateDif class instead * Use the interval method in the DateTimeExcel\DateDif 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::evaluate($startDate, $endDate, $unit); return DateTimeExcel\DateDif::interval($startDate, $endDate, $unit);
} }
/** /**
@ -297,8 +297,8 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\Days::evaluate() * @See DateTimeExcel\Days::between()
* Use the evaluate method in the DateTimeExcel\Days class instead * Use the between method in the DateTimeExcel\Days class instead
* *
* @param DateTimeInterface|float|int|string $endDate Excel date serial value (float), * @param DateTimeInterface|float|int|string $endDate Excel date serial value (float),
* PHP date timestamp (integer), PHP DateTime object, or a standard date string * PHP date timestamp (integer), PHP DateTime object, or a standard date string
@ -309,7 +309,7 @@ class DateTime
*/ */
public static function DAYS($endDate = 0, $startDate = 0) public static function DAYS($endDate = 0, $startDate = 0)
{ {
return DateTimeExcel\Days::evaluate($endDate, $startDate); return DateTimeExcel\Days::between($endDate, $startDate);
} }
/** /**
@ -324,8 +324,8 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\Days360::evaluate() * @See DateTimeExcel\Days360::between()
* Use the evaluate method in the DateTimeExcel\Days360 class instead * Use the between method in the DateTimeExcel\Days360 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
@ -347,7 +347,7 @@ class DateTime
*/ */
public static function DAYS360($startDate = 0, $endDate = 0, $method = false) public static function DAYS360($startDate = 0, $endDate = 0, $method = false)
{ {
return DateTimeExcel\Days360::evaluate($startDate, $endDate, $method); return DateTimeExcel\Days360::between($startDate, $endDate, $method);
} }
/** /**
@ -363,8 +363,8 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\YearFrac::evaluate() * @See DateTimeExcel\YearFrac::fraction()
* Use the evaluate method in the DateTimeExcel\YearFrac class instead * Use the fraction method in the DateTimeExcel\YearFrac class instead
* *
* See https://lists.oasis-open.org/archives/office-formula/200806/msg00039.html * See https://lists.oasis-open.org/archives/office-formula/200806/msg00039.html
* for description of algorithm used in Excel * for description of algorithm used in Excel
@ -384,7 +384,7 @@ class DateTime
*/ */
public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0) public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0)
{ {
return DateTimeExcel\YearFrac::evaluate($startDate, $endDate, $method); return DateTimeExcel\YearFrac::fraction($startDate, $endDate, $method);
} }
/** /**
@ -867,8 +867,8 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\Edate::evaluate() * @See DateTimeExcel\Month::adjust()
* Use the evaluate method in the DateTimeExcel\Edate class instead * Use the adjust method in the DateTimeExcel\Edate class instead
* *
* @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * @param mixed $dateValue 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
@ -881,7 +881,7 @@ class DateTime
*/ */
public static function EDATE($dateValue = 1, $adjustmentMonths = 0) public static function EDATE($dateValue = 1, $adjustmentMonths = 0)
{ {
return DateTimeExcel\EDate::evaluate($dateValue, $adjustmentMonths); return DateTimeExcel\Month::adjust($dateValue, $adjustmentMonths);
} }
/** /**
@ -896,8 +896,8 @@ class DateTime
* *
* @Deprecated 1.18.0 * @Deprecated 1.18.0
* *
* @See DateTimeExcel\EoMonth::evaluate() * @See DateTimeExcel\Month::lastDay()
* Use the evaluate method in the DateTimeExcel\EoMonth class instead * Use the lastDay method in the DateTimeExcel\EoMonth class instead
* *
* @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), * @param mixed $dateValue 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
@ -910,6 +910,6 @@ class DateTime
*/ */
public static function EOMONTH($dateValue = 1, $adjustmentMonths = 0) public static function EOMONTH($dateValue = 1, $adjustmentMonths = 0)
{ {
return DateTimeExcel\EoMonth::evaluate($dateValue, $adjustmentMonths); return DateTimeExcel\Month::lastDay($dateValue, $adjustmentMonths);
} }
} }

View File

@ -21,7 +21,7 @@ class DateDif
* *
* @return int|string Interval between the dates * @return int|string Interval between the dates
*/ */
public static function evaluate($startDate, $endDate, $unit = 'D') public static function interval($startDate, $endDate, $unit = 'D')
{ {
try { try {
$startDate = Helpers::getDateValue($startDate); $startDate = Helpers::getDateValue($startDate);

View File

@ -24,7 +24,7 @@ class Days
* *
* @return int|string Number of days between start date and end date or an error * @return int|string Number of days between start date and end date or an error
*/ */
public static function evaluate($endDate, $startDate) public static function between($endDate, $startDate)
{ {
try { try {
$startDate = Helpers::getDateValue($startDate); $startDate = Helpers::getDateValue($startDate);

View File

@ -36,7 +36,7 @@ class Days360
* *
* @return int|string Number of days between start date and end date * @return int|string Number of days between start date and end date
*/ */
public static function evaluate($startDate = 0, $endDate = 0, $method = false) public static function between($startDate = 0, $endDate = 0, $method = false)
{ {
try { try {
$startDate = Helpers::getDateValue($startDate); $startDate = Helpers::getDateValue($startDate);

View File

@ -1,45 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use Exception;
use PhpOffice\PhpSpreadsheet\Shared\Date;
class EDate
{
/**
* EDATE.
*
* Returns the serial number that represents the date that is the indicated number of months
* before or after a specified date (the start_date).
* Use EDATE to calculate maturity dates or due dates that fall on the same day of the month
* as the date of issue.
*
* Excel Function:
* EDATE(dateValue,adjustmentMonths)
*
* @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.
* A positive value for months yields a future date;
* a negative value yields a past date.
*
* @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 evaluate($dateValue, $adjustmentMonths)
{
try {
$dateValue = Helpers::getDateValue($dateValue, false);
$adjustmentMonths = Helpers::validateNumericNull($adjustmentMonths);
} catch (Exception $e) {
return $e->getMessage();
}
$adjustmentMonths = floor($adjustmentMonths);
// Execute function
$PHPDateObject = Helpers::adjustDateByMonths($dateValue, $adjustmentMonths);
return Helpers::returnIn3FormatsObject($PHPDateObject);
}
}

View File

@ -5,8 +5,44 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use Exception; use Exception;
use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\Date;
class EoMonth class Month
{ {
/**
* EDATE.
*
* Returns the serial number that represents the date that is the indicated number of months
* before or after a specified date (the start_date).
* Use EDATE to calculate maturity dates or due dates that fall on the same day of the month
* as the date of issue.
*
* Excel Function:
* EDATE(dateValue,adjustmentMonths)
*
* @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.
* A positive value for months yields a future date;
* a negative value yields a past date.
*
* @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 adjust($dateValue, $adjustmentMonths)
{
try {
$dateValue = Helpers::getDateValue($dateValue, false);
$adjustmentMonths = Helpers::validateNumericNull($adjustmentMonths);
} catch (Exception $e) {
return $e->getMessage();
}
$adjustmentMonths = floor($adjustmentMonths);
// Execute function
$PHPDateObject = Helpers::adjustDateByMonths($dateValue, $adjustmentMonths);
return Helpers::returnIn3FormatsObject($PHPDateObject);
}
/** /**
* EOMONTH. * EOMONTH.
* *
@ -26,7 +62,7 @@ class EoMonth
* @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, $adjustmentMonths) public static function lastDay($dateValue, $adjustmentMonths)
{ {
try { try {
$dateValue = Helpers::getDateValue($dateValue, false); $dateValue = Helpers::getDateValue($dateValue, false);

View File

@ -34,7 +34,7 @@ class YearFrac
* *
* @return float|string fraction of the year, or a string containing an error * @return float|string fraction of the year, or a string containing an error
*/ */
public static function evaluate($startDate, $endDate, $method = 0) public static function fraction($startDate, $endDate, $method = 0)
{ {
try { try {
$method = (int) Helpers::validateNumericNull($method); $method = (int) Helpers::validateNumericNull($method);
@ -50,15 +50,15 @@ class YearFrac
switch ($method) { switch ($method) {
case 0: case 0:
return Days360::evaluate($startDate, $endDate) / 360; return Days360::between($startDate, $endDate) / 360;
case 1: case 1:
return self::method1($startDate, $endDate); return self::method1($startDate, $endDate);
case 2: case 2:
return DateDif::evaluate($startDate, $endDate) / 360; return DateDif::interval($startDate, $endDate) / 360;
case 3: case 3:
return DateDif::evaluate($startDate, $endDate) / 365; return DateDif::interval($startDate, $endDate) / 365;
case 4: case 4:
return Days360::evaluate($startDate, $endDate, true) / 360; return Days360::between($startDate, $endDate, true) / 360;
} }
return Functions::NAN(); return Functions::NAN();
@ -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::evaluate($startDate, $endDate); $days = DateDif::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

@ -70,7 +70,7 @@ class Amortization
return $e->getMessage(); return $e->getMessage();
} }
$yearFrac = DateTimeExcel\YearFrac::evaluate($purchased, $firstPeriod, $basis); $yearFrac = DateTimeExcel\YearFrac::fraction($purchased, $firstPeriod, $basis);
if (is_string($yearFrac)) { if (is_string($yearFrac)) {
return $yearFrac; return $yearFrac;
} }
@ -161,7 +161,7 @@ class Amortization
$fCostDelta = $cost - $salvage; $fCostDelta = $cost - $salvage;
// Note, quirky variation for leap years on the YEARFRAC for this function // Note, quirky variation for leap years on the YEARFRAC for this function
$purchasedYear = DateTimeExcel\DateParts::year($purchased); $purchasedYear = DateTimeExcel\DateParts::year($purchased);
$yearFrac = DateTimeExcel\YearFrac::evaluate($purchased, $firstPeriod, $basis); $yearFrac = DateTimeExcel\YearFrac::fraction($purchased, $firstPeriod, $basis);
if (is_string($yearFrac)) { if (is_string($yearFrac)) {
return $yearFrac; return $yearFrac;
} }

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::evaluate($datei, $date0, 'd')); $dif = $ordered ? Functions::NAN() : -((int) DateTimeExcel\DateDif::interval($datei, $date0, 'd'));
} else { } else {
$dif = DateTimeExcel\DateDif::evaluate($date0, $datei, 'd'); $dif = DateTimeExcel\DateDif::interval($date0, $datei, 'd');
} }
if (!is_numeric($dif)) { if (!is_numeric($dif)) {
return $dif; return $dif;

View File

@ -70,10 +70,10 @@ class Coupons
$prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS); $prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS);
if ($basis === FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL) { if ($basis === FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL) {
return abs((float) DateTimeExcel\Days::evaluate($prev, $settlement)); return abs((float) DateTimeExcel\Days::between($prev, $settlement));
} }
return DateTimeExcel\YearFrac::evaluate($prev, $settlement, $basis) * $daysPerYear; return DateTimeExcel\YearFrac::fraction($prev, $settlement, $basis) * $daysPerYear;
} }
/** /**
@ -208,7 +208,7 @@ class Coupons
} }
} }
return DateTimeExcel\YearFrac::evaluate($settlement, $next, $basis) * $daysPerYear; return DateTimeExcel\YearFrac::fraction($settlement, $next, $basis) * $daysPerYear;
} }
/** /**
@ -316,7 +316,7 @@ class Coupons
return $e->getMessage(); return $e->getMessage();
} }
$yearsBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate( $yearsBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction(
$settlement, $settlement,
$maturity, $maturity,
FinancialConstants::BASIS_DAYS_PER_YEAR_NASD FinancialConstants::BASIS_DAYS_PER_YEAR_NASD

View File

@ -78,12 +78,12 @@ class AccruedInterest
return $e->getMessage(); return $e->getMessage();
} }
$daysBetweenIssueAndSettlement = YearFrac::evaluate($issue, $settlement, $basis); $daysBetweenIssueAndSettlement = YearFrac::fraction($issue, $settlement, $basis);
if (!is_numeric($daysBetweenIssueAndSettlement)) { if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error // return date error
return $daysBetweenIssueAndSettlement; return $daysBetweenIssueAndSettlement;
} }
$daysBetweenFirstInterestAndSettlement = YearFrac::evaluate($firstInterest, $settlement, $basis); $daysBetweenFirstInterestAndSettlement = YearFrac::fraction($firstInterest, $settlement, $basis);
if (!is_numeric($daysBetweenFirstInterestAndSettlement)) { if (!is_numeric($daysBetweenFirstInterestAndSettlement)) {
// return date error // return date error
return $daysBetweenFirstInterestAndSettlement; return $daysBetweenFirstInterestAndSettlement;
@ -140,7 +140,7 @@ class AccruedInterest
return $e->getMessage(); return $e->getMessage();
} }
$daysBetweenIssueAndSettlement = YearFrac::evaluate($issue, $settlement, $basis); $daysBetweenIssueAndSettlement = YearFrac::fraction($issue, $settlement, $basis);
if (!is_numeric($daysBetweenIssueAndSettlement)) { if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error // return date error
return $daysBetweenIssueAndSettlement; return $daysBetweenIssueAndSettlement;

View File

@ -134,7 +134,7 @@ class Price
return $e->getMessage(); return $e->getMessage();
} }
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;
@ -198,19 +198,19 @@ class Price
if (!is_numeric($daysPerYear)) { if (!is_numeric($daysPerYear)) {
return $daysPerYear; return $daysPerYear;
} }
$daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::evaluate($issue, $settlement, $basis); $daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::fraction($issue, $settlement, $basis);
if (!is_numeric($daysBetweenIssueAndSettlement)) { if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error // return date error
return $daysBetweenIssueAndSettlement; return $daysBetweenIssueAndSettlement;
} }
$daysBetweenIssueAndSettlement *= $daysPerYear; $daysBetweenIssueAndSettlement *= $daysPerYear;
$daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::evaluate($issue, $maturity, $basis); $daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::fraction($issue, $maturity, $basis);
if (!is_numeric($daysBetweenIssueAndMaturity)) { if (!is_numeric($daysBetweenIssueAndMaturity)) {
// return date error // return date error
return $daysBetweenIssueAndMaturity; return $daysBetweenIssueAndMaturity;
} }
$daysBetweenIssueAndMaturity *= $daysPerYear; $daysBetweenIssueAndMaturity *= $daysPerYear;
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;
@ -272,7 +272,7 @@ class Price
if ($investment <= 0) { if ($investment <= 0) {
return Functions::NAN(); return Functions::NAN();
} }
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;

View File

@ -63,7 +63,7 @@ class Rates
return Functions::NAN(); return Functions::NAN();
} }
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;
@ -126,7 +126,7 @@ class Rates
return Functions::NAN(); return Functions::NAN();
} }
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;

View File

@ -61,7 +61,7 @@ class Yields
if (!is_numeric($daysPerYear)) { if (!is_numeric($daysPerYear)) {
return $daysPerYear; return $daysPerYear;
} }
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;
@ -126,19 +126,19 @@ class Yields
if (!is_numeric($daysPerYear)) { if (!is_numeric($daysPerYear)) {
return $daysPerYear; return $daysPerYear;
} }
$daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::evaluate($issue, $settlement, $basis); $daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::fraction($issue, $settlement, $basis);
if (!is_numeric($daysBetweenIssueAndSettlement)) { if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error // return date error
return $daysBetweenIssueAndSettlement; return $daysBetweenIssueAndSettlement;
} }
$daysBetweenIssueAndSettlement *= $daysPerYear; $daysBetweenIssueAndSettlement *= $daysPerYear;
$daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::evaluate($issue, $maturity, $basis); $daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::fraction($issue, $maturity, $basis);
if (!is_numeric($daysBetweenIssueAndMaturity)) { if (!is_numeric($daysBetweenIssueAndMaturity)) {
// return date error // return date error
return $daysBetweenIssueAndMaturity; return $daysBetweenIssueAndMaturity;
} }
$daysBetweenIssueAndMaturity *= $daysPerYear; $daysBetweenIssueAndMaturity *= $daysPerYear;
$daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::evaluate($settlement, $maturity, $basis); $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) { if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error // return date error
return $daysBetweenSettlementAndMaturity; return $daysBetweenSettlementAndMaturity;

View File

@ -33,13 +33,13 @@ class DaysTest extends AllSetupTeardown
{ {
$obj1 = new DateTime('2000-3-31'); $obj1 = new DateTime('2000-3-31');
$obj2 = new DateTimeImmutable('2000-2-29'); $obj2 = new DateTimeImmutable('2000-2-29');
self::assertSame(31, Days::evaluate($obj1, $obj2)); self::assertSame(31, Days::between($obj1, $obj2));
} }
public function testNonDateObject(): void public function testNonDateObject(): void
{ {
$obj1 = new Exception(); $obj1 = new Exception();
$obj2 = new DateTimeImmutable('2000-2-29'); $obj2 = new DateTimeImmutable('2000-2-29');
self::assertSame('#VALUE!', Days::evaluate($obj1, $obj2)); self::assertSame('#VALUE!', Days::between($obj1, $obj2));
} }
} }

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\EDate; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Month;
class EDateTest extends AllSetupTeardown class EDateTest extends AllSetupTeardown
{ {
@ -29,7 +29,7 @@ class EDateTest extends AllSetupTeardown
{ {
self::setUnixReturn(); self::setUnixReturn();
$result = EDate::evaluate('2012-1-26', -1); $result = Month::adjust('2012-1-26', -1);
self::assertEquals(1324857600, $result); self::assertEquals(1324857600, $result);
self::assertEqualsWithDelta(1324857600, $result, 1E-8); self::assertEqualsWithDelta(1324857600, $result, 1E-8);
} }
@ -38,7 +38,7 @@ class EDateTest extends AllSetupTeardown
{ {
self::setObjectReturn(); self::setObjectReturn();
$result = EDate::evaluate('2012-1-26', -1); $result = Month::adjust('2012-1-26', -1);
// Must return an object... // Must return an object...
self::assertIsObject($result); self::assertIsObject($result);
// ... of the correct type // ... of the correct type

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\EoMonth; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Month;
class EoMonthTest extends AllSetupTeardown class EoMonthTest extends AllSetupTeardown
{ {
@ -29,7 +29,7 @@ class EoMonthTest extends AllSetupTeardown
{ {
self::setUnixReturn(); self::setUnixReturn();
$result = EoMonth::evaluate('2012-1-26', -1); $result = Month::lastDay('2012-1-26', -1);
self::assertEquals(1325289600, $result); self::assertEquals(1325289600, $result);
} }
@ -37,7 +37,7 @@ class EoMonthTest extends AllSetupTeardown
{ {
self::setObjectReturn(); self::setObjectReturn();
$result = EoMonth::evaluate('2012-1-26', -1); $result = Month::lastDay('2012-1-26', -1);
// Must return an object... // Must return an object...
self::assertIsObject($result); self::assertIsObject($result);
// ... of the correct type // ... of the correct type