You are here

public static function PHPExcel_Calculation_DateTime::YEARFRAC in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/DateTime.php \PHPExcel_Calculation_DateTime::YEARFRAC()

* YEARFRAC * * Calculates the fraction of the year represented by the number of whole days between two dates * (the start_date and the end_date). * Use the YEARFRAC worksheet function to identify the proportion of a whole year's benefits or * obligations to assign to a specific term. * * Excel Function: * YEARFRAC(startDate,endDate[,method]) * * @access public * @category Date/Time Functions *

Parameters

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 integer $method Method used for the calculation * 0 or omitted US (NASD) 30/360 * 1 Actual/actual * 2 Actual/360 * 3 Actual/365 * 4 European 30/360 * @return float fraction of the year

17 calls to PHPExcel_Calculation_DateTime::YEARFRAC()
PHPExcel_Calculation_Financial::ACCRINT in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php
* ACCRINT * * Returns the accrued interest for a security that pays periodic interest. * * Excel Function: * ACCRINT(issue,firstinterest,settlement,rate,par,frequency[,basis]) * * @access public * @category Financial Functions *
PHPExcel_Calculation_Financial::ACCRINTM in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php
* ACCRINTM * * Returns the accrued interest for a security that pays interest at maturity. * * Excel Function: * ACCRINTM(issue,settlement,rate[,par[,basis]]) * * @access public * @category Financial Functions *
PHPExcel_Calculation_Financial::AMORDEGRC in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php
* AMORDEGRC * * Returns the depreciation for each accounting period. * This function is provided for the French accounting system. If an asset is purchased in * the middle of the accounting period, the prorated depreciation is taken into…
PHPExcel_Calculation_Financial::AMORLINC in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php
* AMORLINC * * Returns the depreciation for each accounting period. * This function is provided for the French accounting system. If an asset is purchased in * the middle of the accounting period, the prorated depreciation is taken into…
PHPExcel_Calculation_Financial::COUPDAYBS in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php
* COUPDAYBS * * Returns the number of days from the beginning of the coupon period to the settlement date. * * Excel Function: * COUPDAYBS(settlement,maturity,frequency[,basis]) * * @access public * @category Financial Functions *

... See full list

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/DateTime.php, line 791

Class

PHPExcel_Calculation_DateTime
PHPExcel_Calculation_DateTime

Code

public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0) {
  $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
  $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);
  $method = PHPExcel_Calculation_Functions::flattenSingleValue($method);
  if (is_string($startDate = self::_getDateValue($startDate))) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  if (is_string($endDate = self::_getDateValue($endDate))) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  if (is_numeric($method) && !is_string($method) || $method == '') {
    switch ($method) {
      case 0:
        return self::DAYS360($startDate, $endDate) / 360;
      case 1:
        $days = self::DATEDIF($startDate, $endDate);
        $startYear = self::YEAR($startDate);
        $endYear = self::YEAR($endDate);
        $years = $endYear - $startYear + 1;
        $leapDays = 0;
        if ($years == 1) {
          if (self::_isLeapYear($endYear)) {
            $startMonth = self::MONTHOFYEAR($startDate);
            $endMonth = self::MONTHOFYEAR($endDate);
            $endDay = self::DAYOFMONTH($endDate);
            if ($startMonth < 3 || $endMonth * 100 + $endDay >= 2 * 100 + 29) {
              $leapDays += 1;
            }
          }
        }
        else {
          for ($year = $startYear; $year <= $endYear; ++$year) {
            if ($year == $startYear) {
              $startMonth = self::MONTHOFYEAR($startDate);
              $startDay = self::DAYOFMONTH($startDate);
              if ($startMonth < 3) {
                $leapDays += self::_isLeapYear($year) ? 1 : 0;
              }
            }
            elseif ($year == $endYear) {
              $endMonth = self::MONTHOFYEAR($endDate);
              $endDay = self::DAYOFMONTH($endDate);
              if ($endMonth * 100 + $endDay >= 2 * 100 + 29) {
                $leapDays += self::_isLeapYear($year) ? 1 : 0;
              }
            }
            else {
              $leapDays += self::_isLeapYear($year) ? 1 : 0;
            }
          }
          if ($years == 2) {
            if ($leapDays == 0 && self::_isLeapYear($startYear) && $days > 365) {
              $leapDays = 1;
            }
            elseif ($days < 366) {
              $years = 1;
            }
          }
          $leapDays /= $years;
        }
        return $days / (365 + $leapDays);
      case 2:
        return self::DATEDIF($startDate, $endDate) / 360;
      case 3:
        return self::DATEDIF($startDate, $endDate) / 365;
      case 4:
        return self::DAYS360($startDate, $endDate, True) / 360;
    }
  }
  return PHPExcel_Calculation_Functions::VALUE();
}