ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
PHPExcel_Calculation_DateTime Class Reference
+ Collaboration diagram for PHPExcel_Calculation_DateTime:

Static Public Member Functions

static _isLeapYear ($year)
 Identify if a year is a leap year or not. More...
 
static _getDateValue ($dateValue)
 _getDateValue More...
 
static DATETIMENOW ()
 
static DATENOW ()
 
static DATE ($year=0, $month=1, $day=1)
 
static TIME ($hour=0, $minute=0, $second=0)
 
static DATEVALUE ($dateValue=1)
 
static TIMEVALUE ($timeValue)
 
static DATEDIF ($startDate=0, $endDate=0, $unit='D')
 DATEDIF. More...
 
static DAYS360 ($startDate=0, $endDate=0, $method=false)
 
static YEARFRAC ($startDate=0, $endDate=0, $method=0)
 
static NETWORKDAYS ($startDate, $endDate)
 
static WORKDAY ($startDate, $endDays)
 
static DAYOFMONTH ($dateValue=1)
 DAYOFMONTH. More...
 
static DAYOFWEEK ($dateValue=1, $style=1)
 DAYOFWEEK. More...
 
static WEEKOFYEAR ($dateValue=1, $method=1)
 WEEKOFYEAR. More...
 
static MONTHOFYEAR ($dateValue=1)
 MONTHOFYEAR. More...
 
static YEAR ($dateValue=1)
 YEAR. More...
 
static HOUROFDAY ($timeValue=0)
 HOUROFDAY. More...
 
static MINUTEOFHOUR ($timeValue=0)
 MINUTEOFHOUR. More...
 
static SECONDOFMINUTE ($timeValue=0)
 SECONDOFMINUTE. More...
 
static EDATE ($dateValue=1, $adjustmentMonths=0)
 EDATE. More...
 
static EOMONTH ($dateValue=1, $adjustmentMonths=0)
 EOMONTH. More...
 

Static Private Member Functions

static _dateDiff360 ($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, $methodUS)
 Return the number of days between two dates based on a 360 day calendar. More...
 
static _getTimeValue ($timeValue)
 _getTimeValue More...
 
static _adjustDateByMonths ($dateValue=0, $adjustmentMonths=0)
 

Detailed Description

Definition at line 46 of file DateTime.php.

Member Function Documentation

◆ _adjustDateByMonths()

static PHPExcel_Calculation_DateTime::_adjustDateByMonths (   $dateValue = 0,
  $adjustmentMonths = 0 
)
staticprivate

Definition at line 135 of file DateTime.php.

135 {
136 // Execute function
137 $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
138 $oMonth = (int) $PHPDateObject->format('m');
139 $oYear = (int) $PHPDateObject->format('Y');
140
141 $adjustmentMonthsString = (string) $adjustmentMonths;
142 if ($adjustmentMonths > 0) {
143 $adjustmentMonthsString = '+'.$adjustmentMonths;
144 }
145 if ($adjustmentMonths != 0) {
146 $PHPDateObject->modify($adjustmentMonthsString.' months');
147 }
148 $nMonth = (int) $PHPDateObject->format('m');
149 $nYear = (int) $PHPDateObject->format('Y');
150
151 $monthDiff = ($nMonth - $oMonth) + (($nYear - $oYear) * 12);
152 if ($monthDiff != $adjustmentMonths) {
153 $adjustDays = (int) $PHPDateObject->format('d');
154 $adjustDaysString = '-'.$adjustDays.' days';
155 $PHPDateObject->modify($adjustDaysString);
156 }
157 return $PHPDateObject;
158 } // function _adjustDateByMonths()
static ExcelToPHPObject($dateValue=0)
Convert a date from Excel to a PHP Date/Time object.
Definition: Date.php:160

References PHPExcel_Shared_Date\ExcelToPHPObject().

Referenced by EDATE(), and EOMONTH().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _dateDiff360()

static PHPExcel_Calculation_DateTime::_dateDiff360 (   $startDay,
  $startMonth,
  $startYear,
  $endDay,
  $endMonth,
  $endYear,
  $methodUS 
)
staticprivate

Return the number of days between two dates based on a 360 day calendar.

Parameters
integer$startDayDay of month of the start date
integer$startMonthMonth of the start date
integer$startYearYear of the start date
integer$endDayDay of month of the start date
integer$endMonthMonth of the start date
integer$endYearYear of the start date
boolean$methodUSWhether to use the US method or the European method of calculation
Returns
integer Number of days between the start date and the end date

Definition at line 71 of file DateTime.php.

71 {
72 if ($startDay == 31) {
73 --$startDay;
74 } elseif ($methodUS && ($startMonth == 2 && ($startDay == 29 || ($startDay == 28 && !self::_isLeapYear($startYear))))) {
75 $startDay = 30;
76 }
77 if ($endDay == 31) {
78 if ($methodUS && $startDay != 30) {
79 $endDay = 1;
80 if ($endMonth == 12) {
81 ++$endYear;
82 $endMonth = 1;
83 } else {
84 ++$endMonth;
85 }
86 } else {
87 $endDay = 30;
88 }
89 }
90
91 return $endDay + $endMonth * 30 + $endYear * 360 - $startDay - $startMonth * 30 - $startYear * 360;
92 } // function _dateDiff360()

References $endYear, and $startYear.

Referenced by DAYS360().

+ Here is the caller graph for this function:

◆ _getDateValue()

static PHPExcel_Calculation_DateTime::_getDateValue (   $dateValue)
static

_getDateValue

Parameters
string$dateValue
Returns
mixed Excel date/time serial value, or string if error

Definition at line 101 of file DateTime.php.

101 {
102 if (!is_numeric($dateValue)) {
103 if ((is_string($dateValue)) &&
106 }
107 if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
108 $dateValue = PHPExcel_Shared_Date::PHPToExcel($dateValue);
109 } else {
112 $dateValue = self::DATEVALUE($dateValue);
114 }
115 }
116 return $dateValue;
117 } // function _getDateValue()
static DATEVALUE($dateValue=1)
Definition: DateTime.php:481
static setReturnDateType($returnDateType)
Definition: Functions.php:155
static PHPToExcel($dateValue=0, $adjustToTimezone=FALSE, $timezone=NULL)
Convert a date from PHP to Excel.
Definition: Date.php:185

References PHPExcel_Calculation_Functions\COMPATIBILITY_GNUMERIC, DATEVALUE(), PHPExcel_Calculation_Functions\getCompatibilityMode(), PHPExcel_Calculation_Functions\getReturnDateType(), PHPExcel_Shared_Date\PHPToExcel(), PHPExcel_Calculation_Functions\RETURNDATE_EXCEL, PHPExcel_Calculation_Functions\setReturnDateType(), and PHPExcel_Calculation_Functions\VALUE().

Referenced by PHPExcel_Calculation_Financial\COUPDAYBS(), PHPExcel_Calculation_Financial\COUPDAYS(), PHPExcel_Calculation_Financial\COUPDAYSNC(), PHPExcel_Calculation_Financial\COUPNCD(), PHPExcel_Calculation_Financial\COUPNUM(), PHPExcel_Calculation_Financial\COUPPCD(), PHPExcel_Calculation_Financial\PRICE(), PHPExcel_Calculation_Financial\TBILLEQ(), PHPExcel_Calculation_Financial\TBILLPRICE(), and PHPExcel_Calculation_Financial\TBILLYIELD().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getTimeValue()

static PHPExcel_Calculation_DateTime::_getTimeValue (   $timeValue)
staticprivate

_getTimeValue

Parameters
string$timeValue
Returns
mixed Excel date/time serial value, or string if error

Definition at line 126 of file DateTime.php.

126 {
129 $timeValue = self::TIMEVALUE($timeValue);
131 return $timeValue;
132 } // function _getTimeValue()
static TIMEVALUE($timeValue)
Definition: DateTime.php:583

References PHPExcel_Calculation_Functions\getReturnDateType(), PHPExcel_Calculation_Functions\RETURNDATE_EXCEL, PHPExcel_Calculation_Functions\setReturnDateType(), and TIMEVALUE().

Referenced by HOUROFDAY(), MINUTEOFHOUR(), and SECONDOFMINUTE().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _isLeapYear()

static PHPExcel_Calculation_DateTime::_isLeapYear (   $year)
static

Identify if a year is a leap year or not.

Parameters
integer$yearThe year to test
Returns
boolean TRUE if the year is a leap year, otherwise FALSE

Definition at line 54 of file DateTime.php.

54 {
55 return ((($year % 4) == 0) && (($year % 100) != 0) || (($year % 400) == 0));
56 } // function _isLeapYear()

Referenced by PHPExcel_Calculation_Financial\_daysPerYear(), PHPExcel_Calculation_Financial\AMORLINC(), and YEARFRAC().

+ Here is the caller graph for this function:

◆ DATE()

static PHPExcel_Calculation_DateTime::DATE (   $year = 0,
  $month = 1,
  $day = 1 
)
static

Definition at line 292 of file DateTime.php.

292 {
296
297 if (($month !== NULL) && (!is_numeric($month))) {
299 }
300
301 if (($day !== NULL) && (!is_numeric($day))) {
303 }
304
305 $year = ($year !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($year) : 0;
306 $month = ($month !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($month) : 0;
307 $day = ($day !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($day) : 0;
308 if ((!is_numeric($year)) ||
309 (!is_numeric($month)) ||
310 (!is_numeric($day))) {
312 }
313 $year = (integer) $year;
314 $month = (integer) $month;
315 $day = (integer) $day;
316
318 // Validate parameters
319 if ($year < ($baseYear-1900)) {
321 }
322 if ((($baseYear-1900) != 0) && ($year < $baseYear) && ($year >= 1900)) {
324 }
325
326 if (($year < $baseYear) && ($year >= ($baseYear-1900))) {
327 $year += 1900;
328 }
329
330 if ($month < 1) {
331 // Handle year/month adjustment if month < 1
332 --$month;
333 $year += ceil($month / 12) - 1;
334 $month = 13 - abs($month % 12);
335 } elseif ($month > 12) {
336 // Handle year/month adjustment if month > 12
337 $year += floor($month / 12);
338 $month = ($month % 12);
339 }
340
341 // Re-validate the year parameter after adjustments
342 if (($year < $baseYear) || ($year >= 10000)) {
344 }
345
346 // Execute function
347 $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year, $month, $day);
350 return (float) $excelDateValue;
352 return (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
354 return PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue);
355 }
356 } // function DATE()
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:662
static FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0)
FormattedPHPToExcel.
Definition: Date.php:215
static dayStringToNumber($day)
Definition: Date.php:385
static monthStringToNumber($month)
Definition: Date.php:374
static getExcelCalendar()
Return the Excel calendar (Windows 1900 or Mac 1904)
Definition: Date.php:106
static ExcelToPHP($dateValue=0, $adjustToTimezone=FALSE, $timezone=NULL)
Convert a date from Excel to PHP.
Definition: Date.php:120
static testStringAsNumeric($value)
Retrieve any leading numeric part of a string, or return the full string if no leading numeric (handl...
Definition: String.php:804

References PHPExcel_Shared_Date\dayStringToNumber(), PHPExcel_Shared_Date\ExcelToPHP(), PHPExcel_Shared_Date\ExcelToPHPObject(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Shared_Date\FormattedPHPToExcel(), PHPExcel_Shared_Date\getExcelCalendar(), PHPExcel_Calculation_Functions\getReturnDateType(), PHPExcel_Shared_Date\monthStringToNumber(), PHPExcel_Calculation_Functions\NaN(), PHPExcel_Calculation_Functions\RETURNDATE_EXCEL, PHPExcel_Calculation_Functions\RETURNDATE_PHP_NUMERIC, PHPExcel_Calculation_Functions\RETURNDATE_PHP_OBJECT, PHPExcel_Shared_String\testStringAsNumeric(), and PHPExcel_Calculation_Functions\VALUE().

Referenced by DateTimeTest\testDATEtoPHP(), DateTimeTest\testDATEtoPHPObject(), DateTimeTest\testDATEwith1904Calendar(), and DateTimeTest\testDATEwith1904CalendarError().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DATEDIF()

static PHPExcel_Calculation_DateTime::DATEDIF (   $startDate = 0,
  $endDate = 0,
  $unit = 'D' 
)
static

DATEDIF.

Parameters
mixed$startDateExcel date serial value, PHP date/time stamp, PHP DateTime object or a standard date string
mixed$endDateExcel date serial value, PHP date/time stamp, PHP DateTime object or a standard date string
string$unit
Returns
integer Interval between the dates

Definition at line 618 of file DateTime.php.

618 {
622
623 if (is_string($startDate = self::_getDateValue($startDate))) {
625 }
626 if (is_string($endDate = self::_getDateValue($endDate))) {
628 }
629
630 // Validate parameters
631 if ($startDate >= $endDate) {
633 }
634
635 // Execute function
636 $difference = $endDate - $startDate;
637
638 $PHPStartDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($startDate);
639 $startDays = $PHPStartDateObject->format('j');
640 $startMonths = $PHPStartDateObject->format('n');
641 $startYears = $PHPStartDateObject->format('Y');
642
643 $PHPEndDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
644 $endDays = $PHPEndDateObject->format('j');
645 $endMonths = $PHPEndDateObject->format('n');
646 $endYears = $PHPEndDateObject->format('Y');
647
649 switch ($unit) {
650 case 'D':
651 $retVal = intval($difference);
652 break;
653 case 'M':
654 $retVal = intval($endMonths - $startMonths) + (intval($endYears - $startYears) * 12);
655 // We're only interested in full months
656 if ($endDays < $startDays) {
657 --$retVal;
658 }
659 break;
660 case 'Y':
661 $retVal = intval($endYears - $startYears);
662 // We're only interested in full months
663 if ($endMonths < $startMonths) {
664 --$retVal;
665 } elseif (($endMonths == $startMonths) && ($endDays < $startDays)) {
666 --$retVal;
667 }
668 break;
669 case 'MD':
670 if ($endDays < $startDays) {
671 $retVal = $endDays;
672 $PHPEndDateObject->modify('-'.$endDays.' days');
673 $adjustDays = $PHPEndDateObject->format('j');
674 if ($adjustDays > $startDays) {
675 $retVal += ($adjustDays - $startDays);
676 }
677 } else {
678 $retVal = $endDays - $startDays;
679 }
680 break;
681 case 'YM':
682 $retVal = intval($endMonths - $startMonths);
683 if ($retVal < 0) $retVal = 12 + $retVal;
684 // We're only interested in full months
685 if ($endDays < $startDays) {
686 --$retVal;
687 }
688 break;
689 case 'YD':
690 $retVal = intval($difference);
691 if ($endYears > $startYears) {
692 while ($endYears > $startYears) {
693 $PHPEndDateObject->modify('-1 year');
694 $endYears = $PHPEndDateObject->format('Y');
695 }
696 $retVal = $PHPEndDateObject->format('z') - $PHPStartDateObject->format('z');
697 if ($retVal < 0) { $retVal += 365; }
698 }
699 break;
700 default:
702 }
703 return $retVal;
704 } // function DATEDIF()

References PHPExcel_Shared_Date\ExcelToPHPObject(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Calculation_Functions\NaN(), and PHPExcel_Calculation_Functions\VALUE().

Referenced by PHPExcel_Calculation_Financial\XNPV(), and YEARFRAC().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DATENOW()

static PHPExcel_Calculation_DateTime::DATENOW ( )
static

Definition at line 220 of file DateTime.php.

220 {
221 $saveTimeZone = date_default_timezone_get();
222 date_default_timezone_set('UTC');
223 $retValue = False;
224 $excelDateTime = floor(PHPExcel_Shared_Date::PHPToExcel(time()));
227 $retValue = (float) $excelDateTime;
228 break;
230 $retValue = (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateTime);
231 break;
233 $retValue = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateTime);
234 break;
235 }
236 date_default_timezone_set($saveTimeZone);
237
238 return $retValue;
239 } // function DATENOW()

References PHPExcel_Shared_Date\ExcelToPHP(), PHPExcel_Shared_Date\ExcelToPHPObject(), PHPExcel_Calculation_Functions\getReturnDateType(), PHPExcel_Shared_Date\PHPToExcel(), PHPExcel_Calculation_Functions\RETURNDATE_EXCEL, PHPExcel_Calculation_Functions\RETURNDATE_PHP_NUMERIC, and PHPExcel_Calculation_Functions\RETURNDATE_PHP_OBJECT.

Referenced by PHPExcel_Worksheet_AutoFilter\_dynamicFilterDateRange().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DATETIMENOW()

static PHPExcel_Calculation_DateTime::DATETIMENOW ( )
static

Definition at line 180 of file DateTime.php.

180 {
181 $saveTimeZone = date_default_timezone_get();
182 date_default_timezone_set('UTC');
183 $retValue = False;
186 $retValue = (float) PHPExcel_Shared_Date::PHPToExcel(time());
187 break;
189 $retValue = (integer) time();
190 break;
192 $retValue = new DateTime();
193 break;
194 }
195 date_default_timezone_set($saveTimeZone);
196
197 return $retValue;
198 } // function DATETIMENOW()

References PHPExcel_Calculation_Functions\getReturnDateType(), PHPExcel_Shared_Date\PHPToExcel(), PHPExcel_Calculation_Functions\RETURNDATE_EXCEL, PHPExcel_Calculation_Functions\RETURNDATE_PHP_NUMERIC, and PHPExcel_Calculation_Functions\RETURNDATE_PHP_OBJECT.

+ Here is the call graph for this function:

◆ DATEVALUE()

static PHPExcel_Calculation_DateTime::DATEVALUE (   $dateValue = 1)
static

Definition at line 481 of file DateTime.php.

481 {
482 $dateValue = trim(PHPExcel_Calculation_Functions::flattenSingleValue($dateValue),'"');
483 // Strip any ordinals because they're allowed in Excel (English only)
484 $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui','$1$3',$dateValue);
485 // Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany)
486 $dateValue = str_replace(array('/','.','-',' '),array(' ',' ',' ',' '),$dateValue);
487
488 $yearFound = false;
489 $t1 = explode(' ',$dateValue);
490 foreach($t1 as &$t) {
491 if ((is_numeric($t)) && ($t > 31)) {
492 if ($yearFound) {
494 } else {
495 if ($t < 100) { $t += 1900; }
496 $yearFound = true;
497 }
498 }
499 }
500 if ((count($t1) == 1) && (strpos($t,':') != false)) {
501 // We've been fed a time value without any date
502 return 0.0;
503 } elseif (count($t1) == 2) {
504 // We only have two parts of the date: either day/month or month/year
505 if ($yearFound) {
506 array_unshift($t1,1);
507 } else {
508 array_push($t1,date('Y'));
509 }
510 }
511 unset($t);
512 $dateValue = implode(' ',$t1);
513
514 $PHPDateArray = date_parse($dateValue);
515 if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0)) {
516 $testVal1 = strtok($dateValue,'- ');
517 if ($testVal1 !== False) {
518 $testVal2 = strtok('- ');
519 if ($testVal2 !== False) {
520 $testVal3 = strtok('- ');
521 if ($testVal3 === False) {
522 $testVal3 = strftime('%Y');
523 }
524 } else {
526 }
527 } else {
529 }
530 $PHPDateArray = date_parse($testVal1.'-'.$testVal2.'-'.$testVal3);
531 if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0)) {
532 $PHPDateArray = date_parse($testVal2.'-'.$testVal1.'-'.$testVal3);
533 if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0)) {
535 }
536 }
537 }
538
539 if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0)) {
540 // Execute function
541 if ($PHPDateArray['year'] == '') { $PHPDateArray['year'] = strftime('%Y'); }
542 if ($PHPDateArray['year'] < 1900)
544 if ($PHPDateArray['month'] == '') { $PHPDateArray['month'] = strftime('%m'); }
545 if ($PHPDateArray['day'] == '') { $PHPDateArray['day'] = strftime('%d'); }
546 $excelDateValue = floor(PHPExcel_Shared_Date::FormattedPHPToExcel($PHPDateArray['year'],$PHPDateArray['month'],$PHPDateArray['day'],$PHPDateArray['hour'],$PHPDateArray['minute'],$PHPDateArray['second']));
547
550 return (float) $excelDateValue;
552 return (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
554 return new DateTime($PHPDateArray['year'].'-'.$PHPDateArray['month'].'-'.$PHPDateArray['day'].' 00:00:00');
555 }
556 }
558 } // function DATEVALUE()
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())

References $t, date, PHPExcel_Shared_Date\ExcelToPHP(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Shared_Date\FormattedPHPToExcel(), PHPExcel_Calculation_Functions\getReturnDateType(), PHPExcel_Calculation_Functions\RETURNDATE_EXCEL, PHPExcel_Calculation_Functions\RETURNDATE_PHP_NUMERIC, PHPExcel_Calculation_Functions\RETURNDATE_PHP_OBJECT, and PHPExcel_Calculation_Functions\VALUE().

Referenced by _getDateValue(), PHPExcel_Shared_Date\stringToExcel(), DateTimeTest\testDATEVALUEtoPHP(), DateTimeTest\testDATEVALUEtoPHPObject(), PHPExcel_Calculation_TextData\TEXTFORMAT(), and PHPExcel_Calculation_TextData\VALUE().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DAYOFMONTH()

static PHPExcel_Calculation_DateTime::DAYOFMONTH (   $dateValue = 1)
static

DAYOFMONTH.

Returns the day of the month, for a specified date. The day is given as an integer ranging from 1 to 31.

Excel Function: DAY(dateValue)

Parameters
mixed$dateValueExcel date serial value (float), PHP date timestamp (integer), PHP DateTime object, or a standard date string
Returns
int Day of the month

Definition at line 1071 of file DateTime.php.

1071 {
1073
1074 if ($dateValue === null) {
1075 $dateValue = 1;
1076 } elseif (is_string($dateValue = self::_getDateValue($dateValue))) {
1078 } elseif ($dateValue == 0.0) {
1079 return 0;
1080 } elseif ($dateValue < 0.0) {
1082 }
1083
1084 // Execute function
1085 $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1086
1087 return (int) $PHPDateObject->format('j');
1088 } // function DAYOFMONTH()

References PHPExcel_Shared_Date\ExcelToPHPObject(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Calculation_Functions\NaN(), and PHPExcel_Calculation_Functions\VALUE().

Referenced by YEARFRAC().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DAYOFWEEK()

static PHPExcel_Calculation_DateTime::DAYOFWEEK (   $dateValue = 1,
  $style = 1 
)
static

DAYOFWEEK.

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).

Excel Function: WEEKDAY(dateValue[,style])

Parameters
mixed$dateValueExcel date serial value (float), PHP date timestamp (integer), PHP DateTime object, or a standard date string
int$styleA 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).
Returns
int Day of the week value

Definition at line 1108 of file DateTime.php.

1108 {
1111
1112 if (!is_numeric($style)) {
1114 } elseif (($style < 1) || ($style > 3)) {
1116 }
1117 $style = floor($style);
1118
1119 if ($dateValue === null) {
1120 $dateValue = 1;
1121 } elseif (is_string($dateValue = self::_getDateValue($dateValue))) {
1123 } elseif ($dateValue < 0.0) {
1125 }
1126
1127 // Execute function
1128 $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1129 $DoW = $PHPDateObject->format('w');
1130
1131 $firstDay = 1;
1132 switch ($style) {
1133 case 1: ++$DoW;
1134 break;
1135 case 2: if ($DoW == 0) { $DoW = 7; }
1136 break;
1137 case 3: if ($DoW == 0) { $DoW = 7; }
1138 $firstDay = 0;
1139 --$DoW;
1140 break;
1141 }
1143 // Test for Excel's 1900 leap year, and introduce the error as required
1144 if (($PHPDateObject->format('Y') == 1900) && ($PHPDateObject->format('n') <= 2)) {
1145 --$DoW;
1146 if ($DoW < $firstDay) {
1147 $DoW += 7;
1148 }
1149 }
1150 }
1151
1152 return (int) $DoW;
1153 } // function DAYOFWEEK()
const COMPATIBILITY_EXCEL
constants
Definition: Functions.php:62
$style
Definition: example_012.php:70

References $style, PHPExcel_Calculation_Functions\COMPATIBILITY_EXCEL, PHPExcel_Shared_Date\ExcelToPHPObject(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Calculation_Functions\getCompatibilityMode(), PHPExcel_Calculation_Functions\NaN(), and PHPExcel_Calculation_Functions\VALUE().

Referenced by NETWORKDAYS(), and WORKDAY().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DAYS360()

static PHPExcel_Calculation_DateTime::DAYS360 (   $startDate = 0,
  $endDate = 0,
  $method = false 
)
static

Definition at line 736 of file DateTime.php.

736 {
739
740 if (is_string($startDate = self::_getDateValue($startDate))) {
742 }
743 if (is_string($endDate = self::_getDateValue($endDate))) {
745 }
746
747 if (!is_bool($method)) {
749 }
750
751 // Execute function
752 $PHPStartDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($startDate);
753 $startDay = $PHPStartDateObject->format('j');
754 $startMonth = $PHPStartDateObject->format('n');
755 $startYear = $PHPStartDateObject->format('Y');
756
757 $PHPEndDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
758 $endDay = $PHPEndDateObject->format('j');
759 $endMonth = $PHPEndDateObject->format('n');
760 $endYear = $PHPEndDateObject->format('Y');
761
762 return self::_dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, !$method);
763 } // function DAYS360()
static _dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, $methodUS)
Return the number of days between two dates based on a 360 day calendar.
Definition: DateTime.php:71

References $endYear, $startYear, _dateDiff360(), PHPExcel_Shared_Date\ExcelToPHPObject(), PHPExcel_Calculation_Functions\flattenSingleValue(), and PHPExcel_Calculation_Functions\VALUE().

Referenced by YEARFRAC().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ EDATE()

static PHPExcel_Calculation_DateTime::EDATE (   $dateValue = 1,
  $adjustmentMonths = 0 
)
static

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)

Parameters
mixed$dateValueExcel date serial value (float), PHP date timestamp (integer), PHP DateTime object, or a standard date string
int$adjustmentMonthsThe number of months before or after start_date. A positive value for months yields a future date; a negative value yields a past date.
Returns
mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, depending on the value of the ReturnDateType flag

Definition at line 1410 of file DateTime.php.

1410 {
1412 $adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths);
1413
1414 if (!is_numeric($adjustmentMonths)) {
1416 }
1417 $adjustmentMonths = floor($adjustmentMonths);
1418
1419 if (is_string($dateValue = self::_getDateValue($dateValue))) {
1421 }
1422
1423 // Execute function
1424 $PHPDateObject = self::_adjustDateByMonths($dateValue,$adjustmentMonths);
1425
1428 return (float) PHPExcel_Shared_Date::PHPToExcel($PHPDateObject);
1432 return $PHPDateObject;
1433 }
1434 } // function EDATE()
static _adjustDateByMonths($dateValue=0, $adjustmentMonths=0)
Definition: DateTime.php:135

References _adjustDateByMonths(), PHPExcel_Shared_Date\ExcelToPHP(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Calculation_Functions\getReturnDateType(), PHPExcel_Shared_Date\PHPToExcel(), PHPExcel_Calculation_Functions\RETURNDATE_EXCEL, PHPExcel_Calculation_Functions\RETURNDATE_PHP_NUMERIC, PHPExcel_Calculation_Functions\RETURNDATE_PHP_OBJECT, and PHPExcel_Calculation_Functions\VALUE().

Referenced by DateTimeTest\testEDATEtoPHP(), and DateTimeTest\testEDATEtoPHPObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ EOMONTH()

static PHPExcel_Calculation_DateTime::EOMONTH (   $dateValue = 1,
  $adjustmentMonths = 0 
)
static

EOMONTH.

Returns the date value for the last day of the month that is the indicated number of months before or after start_date. Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month.

Excel Function: EOMONTH(dateValue,adjustmentMonths)

Parameters
mixed$dateValueExcel date serial value (float), PHP date timestamp (integer), PHP DateTime object, or a standard date string
int$adjustmentMonthsThe number of months before or after start_date. A positive value for months yields a future date; a negative value yields a past date.
Returns
mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, depending on the value of the ReturnDateType flag

Definition at line 1455 of file DateTime.php.

1455 {
1457 $adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths);
1458
1459 if (!is_numeric($adjustmentMonths)) {
1461 }
1462 $adjustmentMonths = floor($adjustmentMonths);
1463
1464 if (is_string($dateValue = self::_getDateValue($dateValue))) {
1466 }
1467
1468 // Execute function
1469 $PHPDateObject = self::_adjustDateByMonths($dateValue,$adjustmentMonths+1);
1470 $adjustDays = (int) $PHPDateObject->format('d');
1471 $adjustDaysString = '-'.$adjustDays.' days';
1472 $PHPDateObject->modify($adjustDaysString);
1473
1476 return (float) PHPExcel_Shared_Date::PHPToExcel($PHPDateObject);
1480 return $PHPDateObject;
1481 }
1482 } // function EOMONTH()

References _adjustDateByMonths(), PHPExcel_Shared_Date\ExcelToPHP(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Calculation_Functions\getReturnDateType(), PHPExcel_Shared_Date\PHPToExcel(), PHPExcel_Calculation_Functions\RETURNDATE_EXCEL, PHPExcel_Calculation_Functions\RETURNDATE_PHP_NUMERIC, PHPExcel_Calculation_Functions\RETURNDATE_PHP_OBJECT, and PHPExcel_Calculation_Functions\VALUE().

Referenced by DateTimeTest\testEOMONTHtoPHP(), and DateTimeTest\testEOMONTHtoPHPObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HOUROFDAY()

static PHPExcel_Calculation_DateTime::HOUROFDAY (   $timeValue = 0)
static

HOUROFDAY.

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.).

Excel Function: HOUR(timeValue)

Parameters
mixed$timeValueExcel date serial value (float), PHP date timestamp (integer), PHP DateTime object, or a standard time string
Returns
int Hour

Definition at line 1284 of file DateTime.php.

1284 {
1286
1287 if (!is_numeric($timeValue)) {
1289 $testVal = strtok($timeValue,'/-: ');
1290 if (strlen($testVal) < strlen($timeValue)) {
1292 }
1293 }
1294 $timeValue = self::_getTimeValue($timeValue);
1295 if (is_string($timeValue)) {
1297 }
1298 }
1299 // Execute function
1300 if ($timeValue >= 1) {
1301 $timeValue = fmod($timeValue,1);
1302 } elseif ($timeValue < 0.0) {
1304 }
1305 $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
1306
1307 return (int) gmdate('G',$timeValue);
1308 } // function HOUROFDAY()
static _getTimeValue($timeValue)
_getTimeValue
Definition: DateTime.php:126

References _getTimeValue(), PHPExcel_Calculation_Functions\COMPATIBILITY_GNUMERIC, PHPExcel_Shared_Date\ExcelToPHP(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Calculation_Functions\getCompatibilityMode(), PHPExcel_Calculation_Functions\NaN(), and PHPExcel_Calculation_Functions\VALUE().

+ Here is the call graph for this function:

◆ MINUTEOFHOUR()

static PHPExcel_Calculation_DateTime::MINUTEOFHOUR (   $timeValue = 0)
static

MINUTEOFHOUR.

Returns the minutes of a time value. The minute is given as an integer, ranging from 0 to 59.

Excel Function: MINUTE(timeValue)

Parameters
mixed$timeValueExcel date serial value (float), PHP date timestamp (integer), PHP DateTime object, or a standard time string
Returns
int Minute

Definition at line 1324 of file DateTime.php.

1324 {
1325 $timeValue = $timeTester = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue);
1326
1327 if (!is_numeric($timeValue)) {
1329 $testVal = strtok($timeValue,'/-: ');
1330 if (strlen($testVal) < strlen($timeValue)) {
1332 }
1333 }
1334 $timeValue = self::_getTimeValue($timeValue);
1335 if (is_string($timeValue)) {
1337 }
1338 }
1339 // Execute function
1340 if ($timeValue >= 1) {
1341 $timeValue = fmod($timeValue,1);
1342 } elseif ($timeValue < 0.0) {
1344 }
1345 $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
1346
1347 return (int) gmdate('i',$timeValue);
1348 } // function MINUTEOFHOUR()

References _getTimeValue(), PHPExcel_Calculation_Functions\COMPATIBILITY_GNUMERIC, PHPExcel_Shared_Date\ExcelToPHP(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Calculation_Functions\getCompatibilityMode(), PHPExcel_Calculation_Functions\NaN(), and PHPExcel_Calculation_Functions\VALUE().

+ Here is the call graph for this function:

◆ MONTHOFYEAR()

static PHPExcel_Calculation_DateTime::MONTHOFYEAR (   $dateValue = 1)
static

MONTHOFYEAR.

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).

Excel Function: MONTH(dateValue)

Parameters
mixed$dateValueExcel date serial value (float), PHP date timestamp (integer), PHP DateTime object, or a standard date string
Returns
int Month of the year

Definition at line 1222 of file DateTime.php.

1222 {
1224
1225 if ($dateValue === null) {
1226 $dateValue = 1;
1227 } elseif (is_string($dateValue = self::_getDateValue($dateValue))) {
1229 } elseif ($dateValue < 0.0) {
1231 }
1232
1233 // Execute function
1234 $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1235
1236 return (int) $PHPDateObject->format('n');
1237 } // function MONTHOFYEAR()

References PHPExcel_Shared_Date\ExcelToPHPObject(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Calculation_Functions\NaN(), and PHPExcel_Calculation_Functions\VALUE().

Referenced by YEARFRAC().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NETWORKDAYS()

static PHPExcel_Calculation_DateTime::NETWORKDAYS (   $startDate,
  $endDate 
)
static

Definition at line 886 of file DateTime.php.

886 {
887 // Retrieve the mandatory start and end date that are referenced in the function definition
890 // Flush the mandatory start and end date that are referenced in the function definition, and get the optional days
891 $dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
892 array_shift($dateArgs);
893 array_shift($dateArgs);
894
895 // Validate the start and end dates
896 if (is_string($startDate = $sDate = self::_getDateValue($startDate))) {
898 }
899 $startDate = (float) floor($startDate);
900 if (is_string($endDate = $eDate = self::_getDateValue($endDate))) {
902 }
903 $endDate = (float) floor($endDate);
904
905 if ($sDate > $eDate) {
906 $startDate = $eDate;
907 $endDate = $sDate;
908 }
909
910 // Execute function
911 $startDoW = 6 - self::DAYOFWEEK($startDate,2);
912 if ($startDoW < 0) { $startDoW = 0; }
913 $endDoW = self::DAYOFWEEK($endDate,2);
914 if ($endDoW >= 6) { $endDoW = 0; }
915
916 $wholeWeekDays = floor(($endDate - $startDate) / 7) * 5;
917 $partWeekDays = $endDoW + $startDoW;
918 if ($partWeekDays > 5) {
919 $partWeekDays -= 5;
920 }
921
922 // Test any extra holiday parameters
923 $holidayCountedArray = array();
924 foreach ($dateArgs as $holidayDate) {
925 if (is_string($holidayDate = self::_getDateValue($holidayDate))) {
927 }
928 if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) {
929 if ((self::DAYOFWEEK($holidayDate,2) < 6) && (!in_array($holidayDate,$holidayCountedArray))) {
930 --$partWeekDays;
931 $holidayCountedArray[] = $holidayDate;
932 }
933 }
934 }
935
936 if ($sDate > $eDate) {
937 return 0 - ($wholeWeekDays + $partWeekDays);
938 }
939 return $wholeWeekDays + $partWeekDays;
940 } // function NETWORKDAYS()
static DAYOFWEEK($dateValue=1, $style=1)
DAYOFWEEK.
Definition: DateTime.php:1108
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
Definition: Functions.php:598

References DAYOFWEEK(), PHPExcel_Calculation_Functions\flattenArray(), PHPExcel_Calculation_Functions\flattenSingleValue(), and PHPExcel_Calculation_Functions\VALUE().

+ Here is the call graph for this function:

◆ SECONDOFMINUTE()

static PHPExcel_Calculation_DateTime::SECONDOFMINUTE (   $timeValue = 0)
static

SECONDOFMINUTE.

Returns the seconds of a time value. The second is given as an integer in the range 0 (zero) to 59.

Excel Function: SECOND(timeValue)

Parameters
mixed$timeValueExcel date serial value (float), PHP date timestamp (integer), PHP DateTime object, or a standard time string
Returns
int Second

Definition at line 1364 of file DateTime.php.

1364 {
1366
1367 if (!is_numeric($timeValue)) {
1369 $testVal = strtok($timeValue,'/-: ');
1370 if (strlen($testVal) < strlen($timeValue)) {
1372 }
1373 }
1374 $timeValue = self::_getTimeValue($timeValue);
1375 if (is_string($timeValue)) {
1377 }
1378 }
1379 // Execute function
1380 if ($timeValue >= 1) {
1381 $timeValue = fmod($timeValue,1);
1382 } elseif ($timeValue < 0.0) {
1384 }
1385 $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
1386
1387 return (int) gmdate('s',$timeValue);
1388 } // function SECONDOFMINUTE()

References _getTimeValue(), PHPExcel_Calculation_Functions\COMPATIBILITY_GNUMERIC, PHPExcel_Shared_Date\ExcelToPHP(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Calculation_Functions\getCompatibilityMode(), PHPExcel_Calculation_Functions\NaN(), and PHPExcel_Calculation_Functions\VALUE().

+ Here is the call graph for this function:

◆ TIME()

static PHPExcel_Calculation_DateTime::TIME (   $hour = 0,
  $minute = 0,
  $second = 0 
)
static

Definition at line 386 of file DateTime.php.

386 {
390
391 if ($hour == '') { $hour = 0; }
392 if ($minute == '') { $minute = 0; }
393 if ($second == '') { $second = 0; }
394
395 if ((!is_numeric($hour)) || (!is_numeric($minute)) || (!is_numeric($second))) {
397 }
398 $hour = (integer) $hour;
399 $minute = (integer) $minute;
400 $second = (integer) $second;
401
402 if ($second < 0) {
403 $minute += floor($second / 60);
404 $second = 60 - abs($second % 60);
405 if ($second == 60) { $second = 0; }
406 } elseif ($second >= 60) {
407 $minute += floor($second / 60);
408 $second = $second % 60;
409 }
410 if ($minute < 0) {
411 $hour += floor($minute / 60);
412 $minute = 60 - abs($minute % 60);
413 if ($minute == 60) { $minute = 0; }
414 } elseif ($minute >= 60) {
415 $hour += floor($minute / 60);
416 $minute = $minute % 60;
417 }
418
419 if ($hour > 23) {
420 $hour = $hour % 24;
421 } elseif ($hour < 0) {
423 }
424
425 // Execute function
428 $date = 0;
431 $date = 1;
432 }
433 return (float) PHPExcel_Shared_Date::FormattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second);
435 return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::FormattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600
437 $dayAdjust = 0;
438 if ($hour < 0) {
439 $dayAdjust = floor($hour / 24);
440 $hour = 24 - abs($hour % 24);
441 if ($hour == 24) { $hour = 0; }
442 } elseif ($hour >= 24) {
443 $dayAdjust = floor($hour / 24);
444 $hour = $hour % 24;
445 }
446 $phpDateObject = new DateTime('1900-01-01 '.$hour.':'.$minute.':'.$second);
447 if ($dayAdjust != 0) {
448 $phpDateObject->modify($dayAdjust.' days');
449 }
450 return $phpDateObject;
451 }
452 } // function TIME()
const CALENDAR_WINDOWS_1900
constants
Definition: Date.php:40

References PHPExcel_Shared_Date\CALENDAR_WINDOWS_1900, PHPExcel_Shared_Date\ExcelToPHP(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Shared_Date\FormattedPHPToExcel(), PHPExcel_Shared_Date\getExcelCalendar(), PHPExcel_Calculation_Functions\getReturnDateType(), PHPExcel_Calculation_Functions\NaN(), PHPExcel_Calculation_Functions\RETURNDATE_EXCEL, PHPExcel_Calculation_Functions\RETURNDATE_PHP_NUMERIC, PHPExcel_Calculation_Functions\RETURNDATE_PHP_OBJECT, and PHPExcel_Calculation_Functions\VALUE().

Referenced by DateTimeTest\testTIMEtoPHP(), and DateTimeTest\testTIMEtoPHPObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TIMEVALUE()

static PHPExcel_Calculation_DateTime::TIMEVALUE (   $timeValue)
static

Definition at line 583 of file DateTime.php.

583 {
584 $timeValue = trim(PHPExcel_Calculation_Functions::flattenSingleValue($timeValue),'"');
585 $timeValue = str_replace(array('/','.'),array('-','-'),$timeValue);
586
587 $PHPDateArray = date_parse($timeValue);
588 if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0)) {
590 $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel($PHPDateArray['year'],$PHPDateArray['month'],$PHPDateArray['day'],$PHPDateArray['hour'],$PHPDateArray['minute'],$PHPDateArray['second']);
591 } else {
592 $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel(1900,1,1,$PHPDateArray['hour'],$PHPDateArray['minute'],$PHPDateArray['second']) - 1;
593 }
594
597 return (float) $excelDateValue;
599 return (integer) $phpDateValue = PHPExcel_Shared_Date::ExcelToPHP($excelDateValue+25569) - 3600;;
601 return new DateTime('1900-01-01 '.$PHPDateArray['hour'].':'.$PHPDateArray['minute'].':'.$PHPDateArray['second']);
602 }
603 }
605 } // function TIMEVALUE()

References PHPExcel_Calculation_Functions\COMPATIBILITY_OPENOFFICE, PHPExcel_Shared_Date\ExcelToPHP(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Shared_Date\FormattedPHPToExcel(), PHPExcel_Calculation_Functions\getCompatibilityMode(), PHPExcel_Calculation_Functions\getReturnDateType(), PHPExcel_Calculation_Functions\RETURNDATE_EXCEL, PHPExcel_Calculation_Functions\RETURNDATE_PHP_NUMERIC, PHPExcel_Calculation_Functions\RETURNDATE_PHP_OBJECT, and PHPExcel_Calculation_Functions\VALUE().

Referenced by _getTimeValue(), PHPExcel_Shared_Date\stringToExcel(), DateTimeTest\testTIMEVALUEtoPHP(), DateTimeTest\testTIMEVALUEtoPHPObject(), and PHPExcel_Calculation_TextData\VALUE().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WEEKOFYEAR()

static PHPExcel_Calculation_DateTime::WEEKOFYEAR (   $dateValue = 1,
  $method = 1 
)
static

WEEKOFYEAR.

Returns the week of the year for a specified date. The WEEKNUM function considers the week containing January 1 to be the first week of the year. However, there is a European standard that defines the first week as the one with the majority of days (four or more) falling in the new year. This means that for years in which there are three days or less in the first week of January, the WEEKNUM function returns week numbers that are incorrect according to the European standard.

Excel Function: WEEKNUM(dateValue[,style])

Parameters
mixed$dateValueExcel date serial value (float), PHP date timestamp (integer), PHP DateTime object, or a standard date string
boolean$methodWeek begins on Sunday or Monday 1 or omitted Week begins on Sunday. 2 Week begins on Monday.
Returns
int Week Number

Definition at line 1176 of file DateTime.php.

1176 {
1179
1180 if (!is_numeric($method)) {
1182 } elseif (($method < 1) || ($method > 2)) {
1184 }
1185 $method = floor($method);
1186
1187 if ($dateValue === null) {
1188 $dateValue = 1;
1189 } elseif (is_string($dateValue = self::_getDateValue($dateValue))) {
1191 } elseif ($dateValue < 0.0) {
1193 }
1194
1195 // Execute function
1196 $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1197 $dayOfYear = $PHPDateObject->format('z');
1198 $dow = $PHPDateObject->format('w');
1199 $PHPDateObject->modify('-'.$dayOfYear.' days');
1200 $dow = $PHPDateObject->format('w');
1201 $daysInFirstWeek = 7 - (($dow + (2 - $method)) % 7);
1202 $dayOfYear -= $daysInFirstWeek;
1203 $weekOfYear = ceil($dayOfYear / 7) + 1;
1204
1205 return (int) $weekOfYear;
1206 } // function WEEKOFYEAR()

References PHPExcel_Shared_Date\ExcelToPHPObject(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Calculation_Functions\NaN(), and PHPExcel_Calculation_Functions\VALUE().

+ Here is the call graph for this function:

◆ WORKDAY()

static PHPExcel_Calculation_DateTime::WORKDAY (   $startDate,
  $endDays 
)
static

Definition at line 968 of file DateTime.php.

968 {
969 // Retrieve the mandatory start date and days that are referenced in the function definition
972 // Flush the mandatory start date and days that are referenced in the function definition, and get the optional days
973 $dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
974 array_shift($dateArgs);
975 array_shift($dateArgs);
976
977 if ((is_string($startDate = self::_getDateValue($startDate))) || (!is_numeric($endDays))) {
979 }
980 $startDate = (float) floor($startDate);
981 $endDays = (int) floor($endDays);
982 // If endDays is 0, we always return startDate
983 if ($endDays == 0) { return $startDate; }
984
985 $decrementing = ($endDays < 0) ? True : False;
986
987 // Adjust the start date if it falls over a weekend
988
989 $startDoW = self::DAYOFWEEK($startDate,3);
990 if (self::DAYOFWEEK($startDate,3) >= 5) {
991 $startDate += ($decrementing) ? -$startDoW + 4: 7 - $startDoW;
992 ($decrementing) ? $endDays++ : $endDays--;
993 }
994
995 // Add endDays
996 $endDate = (float) $startDate + (intval($endDays / 5) * 7) + ($endDays % 5);
997
998 // Adjust the calculated end date if it falls over a weekend
999 $endDoW = self::DAYOFWEEK($endDate,3);
1000 if ($endDoW >= 5) {
1001 $endDate += ($decrementing) ? -$endDoW + 4: 7 - $endDoW;
1002 }
1003
1004 // Test any extra holiday parameters
1005 if (!empty($dateArgs)) {
1006 $holidayCountedArray = $holidayDates = array();
1007 foreach ($dateArgs as $holidayDate) {
1008 if (($holidayDate !== NULL) && (trim($holidayDate) > '')) {
1009 if (is_string($holidayDate = self::_getDateValue($holidayDate))) {
1011 }
1012 if (self::DAYOFWEEK($holidayDate,3) < 5) {
1013 $holidayDates[] = $holidayDate;
1014 }
1015 }
1016 }
1017 if ($decrementing) {
1018 rsort($holidayDates, SORT_NUMERIC);
1019 } else {
1020 sort($holidayDates, SORT_NUMERIC);
1021 }
1022 foreach ($holidayDates as $holidayDate) {
1023 if ($decrementing) {
1024 if (($holidayDate <= $startDate) && ($holidayDate >= $endDate)) {
1025 if (!in_array($holidayDate,$holidayCountedArray)) {
1026 --$endDate;
1027 $holidayCountedArray[] = $holidayDate;
1028 }
1029 }
1030 } else {
1031 if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) {
1032 if (!in_array($holidayDate,$holidayCountedArray)) {
1033 ++$endDate;
1034 $holidayCountedArray[] = $holidayDate;
1035 }
1036 }
1037 }
1038 // Adjust the calculated end date if it falls over a weekend
1039 $endDoW = self::DAYOFWEEK($endDate,3);
1040 if ($endDoW >= 5) {
1041 $endDate += ($decrementing) ? -$endDoW + 4: 7 - $endDoW;
1042 }
1043
1044 }
1045 }
1046
1049 return (float) $endDate;
1051 return (integer) PHPExcel_Shared_Date::ExcelToPHP($endDate);
1054 }
1055 } // function WORKDAY()

References DAYOFWEEK(), PHPExcel_Shared_Date\ExcelToPHP(), PHPExcel_Shared_Date\ExcelToPHPObject(), PHPExcel_Calculation_Functions\flattenArray(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Calculation_Functions\getReturnDateType(), PHPExcel_Calculation_Functions\RETURNDATE_EXCEL, PHPExcel_Calculation_Functions\RETURNDATE_PHP_NUMERIC, PHPExcel_Calculation_Functions\RETURNDATE_PHP_OBJECT, and PHPExcel_Calculation_Functions\VALUE().

+ Here is the call graph for this function:

◆ YEAR()

static PHPExcel_Calculation_DateTime::YEAR (   $dateValue = 1)
static

YEAR.

Returns the year corresponding to a date. The year is returned as an integer in the range 1900-9999.

Excel Function: YEAR(dateValue)

Parameters
mixed$dateValueExcel date serial value (float), PHP date timestamp (integer), PHP DateTime object, or a standard date string
Returns
int Year

Definition at line 1253 of file DateTime.php.

1253 {
1255
1256 if ($dateValue === null) {
1257 $dateValue = 1;
1258 } elseif (is_string($dateValue = self::_getDateValue($dateValue))) {
1260 } elseif ($dateValue < 0.0) {
1262 }
1263
1264 // Execute function
1265 $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1266
1267 return (int) $PHPDateObject->format('Y');
1268 } // function YEAR()

References PHPExcel_Shared_Date\ExcelToPHPObject(), PHPExcel_Calculation_Functions\flattenSingleValue(), PHPExcel_Calculation_Functions\NaN(), and PHPExcel_Calculation_Functions\VALUE().

Referenced by PHPExcel_Calculation_Financial\AMORLINC(), PHPExcel_Calculation_Financial\COUPDAYBS(), PHPExcel_Calculation_Financial\COUPDAYS(), PHPExcel_Calculation_Financial\COUPDAYSNC(), PHPExcel_Calculation_Financial\PRICEMAT(), YEARFRAC(), PHPExcel_Calculation_Financial\YIELDDISC(), and PHPExcel_Calculation_Financial\YIELDMAT().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ YEARFRAC()

static PHPExcel_Calculation_DateTime::YEARFRAC (   $startDate = 0,
  $endDate = 0,
  $method = 0 
)
static

Definition at line 791 of file DateTime.php.

791 {
795
796 if (is_string($startDate = self::_getDateValue($startDate))) {
798 }
799 if (is_string($endDate = self::_getDateValue($endDate))) {
801 }
802
803 if (((is_numeric($method)) && (!is_string($method))) || ($method == '')) {
804 switch($method) {
805 case 0 :
806 return self::DAYS360($startDate,$endDate) / 360;
807 case 1 :
808 $days = self::DATEDIF($startDate,$endDate);
809 $startYear = self::YEAR($startDate);
810 $endYear = self::YEAR($endDate);
811 $years = $endYear - $startYear + 1;
812 $leapDays = 0;
813 if ($years == 1) {
814 if (self::_isLeapYear($endYear)) {
815 $startMonth = self::MONTHOFYEAR($startDate);
816 $endMonth = self::MONTHOFYEAR($endDate);
817 $endDay = self::DAYOFMONTH($endDate);
818 if (($startMonth < 3) ||
819 (($endMonth * 100 + $endDay) >= (2 * 100 + 29))) {
820 $leapDays += 1;
821 }
822 }
823 } else {
824 for($year = $startYear; $year <= $endYear; ++$year) {
825 if ($year == $startYear) {
826 $startMonth = self::MONTHOFYEAR($startDate);
827 $startDay = self::DAYOFMONTH($startDate);
828 if ($startMonth < 3) {
829 $leapDays += (self::_isLeapYear($year)) ? 1 : 0;
830 }
831 } elseif($year == $endYear) {
832 $endMonth = self::MONTHOFYEAR($endDate);
833 $endDay = self::DAYOFMONTH($endDate);
834 if (($endMonth * 100 + $endDay) >= (2 * 100 + 29)) {
835 $leapDays += (self::_isLeapYear($year)) ? 1 : 0;
836 }
837 } else {
838 $leapDays += (self::_isLeapYear($year)) ? 1 : 0;
839 }
840 }
841 if ($years == 2) {
842 if (($leapDays == 0) && (self::_isLeapYear($startYear)) && ($days > 365)) {
843 $leapDays = 1;
844 } elseif ($days < 366) {
845 $years = 1;
846 }
847 }
848 $leapDays /= $years;
849 }
850 return $days / (365 + $leapDays);
851 case 2 :
852 return self::DATEDIF($startDate,$endDate) / 360;
853 case 3 :
854 return self::DATEDIF($startDate,$endDate) / 365;
855 case 4 :
856 return self::DAYS360($startDate,$endDate,True) / 360;
857 }
858 }
860 } // function YEARFRAC()
static YEAR($dateValue=1)
YEAR.
Definition: DateTime.php:1253
static DAYOFMONTH($dateValue=1)
DAYOFMONTH.
Definition: DateTime.php:1071
static MONTHOFYEAR($dateValue=1)
MONTHOFYEAR.
Definition: DateTime.php:1222
static DATEDIF($startDate=0, $endDate=0, $unit='D')
DATEDIF.
Definition: DateTime.php:618
static _isLeapYear($year)
Identify if a year is a leap year or not.
Definition: DateTime.php:54
static DAYS360($startDate=0, $endDate=0, $method=false)
Definition: DateTime.php:736

References $endYear, $startYear, $years, _isLeapYear(), DATEDIF(), DAYOFMONTH(), DAYS360(), PHPExcel_Calculation_Functions\flattenSingleValue(), MONTHOFYEAR(), PHPExcel_Calculation_Functions\VALUE(), and YEAR().

Referenced by PHPExcel_Calculation_Financial\ACCRINT(), PHPExcel_Calculation_Financial\ACCRINTM(), PHPExcel_Calculation_Financial\AMORDEGRC(), PHPExcel_Calculation_Financial\AMORLINC(), PHPExcel_Calculation_Financial\COUPDAYBS(), PHPExcel_Calculation_Financial\COUPDAYSNC(), PHPExcel_Calculation_Financial\COUPNUM(), PHPExcel_Calculation_Financial\DISC(), PHPExcel_Calculation_Financial\INTRATE(), PHPExcel_Calculation_Financial\PRICEDISC(), PHPExcel_Calculation_Financial\PRICEMAT(), PHPExcel_Calculation_Financial\RECEIVED(), PHPExcel_Calculation_Financial\TBILLEQ(), PHPExcel_Calculation_Financial\TBILLPRICE(), PHPExcel_Calculation_Financial\TBILLYIELD(), PHPExcel_Calculation_Financial\YIELDDISC(), and PHPExcel_Calculation_Financial\YIELDMAT().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: