Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like DateTime often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DateTime, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class DateTime |
||
28 | { |
||
29 | /** |
||
30 | * Identify if a year is a leap year or not |
||
31 | * |
||
32 | * @param int $year The year to test |
||
33 | * @return bool TRUE if the year is a leap year, otherwise FALSE |
||
34 | */ |
||
35 | 20 | public static function isLeapYear($year) |
|
39 | |||
40 | /** |
||
41 | * Return the number of days between two dates based on a 360 day calendar |
||
42 | * |
||
43 | * @param int $startDay Day of month of the start date |
||
44 | * @param int $startMonth Month of the start date |
||
45 | * @param int $startYear Year of the start date |
||
46 | * @param int $endDay Day of month of the start date |
||
47 | * @param int $endMonth Month of the start date |
||
48 | * @param int $endYear Year of the start date |
||
49 | * @param bool $methodUS Whether to use the US method or the European method of calculation |
||
50 | * @return int Number of days between the start date and the end date |
||
51 | */ |
||
52 | 68 | private static function dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, $methodUS) |
|
75 | |||
76 | /** |
||
77 | * getDateValue |
||
78 | * |
||
79 | * @param string $dateValue |
||
80 | * @return mixed Excel date/time serial value, or string if error |
||
81 | */ |
||
82 | 381 | public static function getDateValue($dateValue) |
|
101 | |||
102 | /** |
||
103 | * getTimeValue |
||
104 | * |
||
105 | * @param string $timeValue |
||
106 | * @return mixed Excel date/time serial value, or string if error |
||
107 | */ |
||
108 | 12 | private static function getTimeValue($timeValue) |
|
117 | |||
118 | 32 | private static function adjustDateByMonths($dateValue = 0, $adjustmentMonths = 0) |
|
144 | |||
145 | /** |
||
146 | * DATETIMENOW |
||
147 | * |
||
148 | * Returns the current date and time. |
||
149 | * The NOW function is useful when you need to display the current date and time on a worksheet or |
||
150 | * calculate a value based on the current date and time, and have that value updated each time you |
||
151 | * open the worksheet. |
||
152 | * |
||
153 | * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date |
||
154 | * and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. |
||
155 | * |
||
156 | * Excel Function: |
||
157 | * NOW() |
||
158 | * |
||
159 | * @category Date/Time Functions |
||
160 | * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
||
161 | * depending on the value of the ReturnDateType flag |
||
162 | */ |
||
163 | public static function DATETIMENOW() |
||
183 | |||
184 | /** |
||
185 | * DATENOW |
||
186 | * |
||
187 | * Returns the current date. |
||
188 | * The NOW function is useful when you need to display the current date and time on a worksheet or |
||
189 | * calculate a value based on the current date and time, and have that value updated each time you |
||
190 | * open the worksheet. |
||
191 | * |
||
192 | * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date |
||
193 | * and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. |
||
194 | * |
||
195 | * Excel Function: |
||
196 | * TODAY() |
||
197 | * |
||
198 | * @category Date/Time Functions |
||
199 | * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
||
200 | * depending on the value of the ReturnDateType flag |
||
201 | */ |
||
202 | 1 | public static function DATENOW() |
|
223 | |||
224 | /** |
||
225 | * DATE |
||
226 | * |
||
227 | * The DATE function returns a value that represents a particular date. |
||
228 | * |
||
229 | * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date |
||
230 | * format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. |
||
231 | * |
||
232 | * Excel Function: |
||
233 | * DATE(year,month,day) |
||
234 | * |
||
235 | * PhpSpreadsheet is a lot more forgiving than MS Excel when passing non numeric values to this function. |
||
236 | * A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted, |
||
237 | * as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language. |
||
238 | * |
||
239 | * @category Date/Time Functions |
||
240 | * @param int $year The value of the year argument can include one to four digits. |
||
241 | * Excel interprets the year argument according to the configured |
||
242 | * date system: 1900 or 1904. |
||
243 | * If year is between 0 (zero) and 1899 (inclusive), Excel adds that |
||
244 | * value to 1900 to calculate the year. For example, DATE(108,1,2) |
||
245 | * returns January 2, 2008 (1900+108). |
||
246 | * If year is between 1900 and 9999 (inclusive), Excel uses that |
||
247 | * value as the year. For example, DATE(2008,1,2) returns January 2, |
||
248 | * 2008. |
||
249 | * If year is less than 0 or is 10000 or greater, Excel returns the |
||
250 | * #NUM! error value. |
||
251 | * @param int $month A positive or negative integer representing the month of the year |
||
252 | * from 1 to 12 (January to December). |
||
253 | * If month is greater than 12, month adds that number of months to |
||
254 | * the first month in the year specified. For example, DATE(2008,14,2) |
||
255 | * returns the serial number representing February 2, 2009. |
||
256 | * If month is less than 1, month subtracts the magnitude of that |
||
257 | * number of months, plus 1, from the first month in the year |
||
258 | * specified. For example, DATE(2008,-3,2) returns the serial number |
||
259 | * representing September 2, 2007. |
||
260 | * @param int $day A positive or negative integer representing the day of the month |
||
261 | * from 1 to 31. |
||
262 | * If day is greater than the number of days in the month specified, |
||
263 | * day adds that number of days to the first day in the month. For |
||
264 | * example, DATE(2008,1,35) returns the serial number representing |
||
265 | * February 4, 2008. |
||
266 | * If day is less than 1, day subtracts the magnitude that number of |
||
267 | * days, plus one, from the first day of the month specified. For |
||
268 | * example, DATE(2008,1,-15) returns the serial number representing |
||
269 | * December 16, 2007. |
||
270 | * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
||
271 | * depending on the value of the ReturnDateType flag |
||
272 | */ |
||
273 | 83 | public static function DATE($year = 0, $month = 1, $day = 1) |
|
339 | |||
340 | /** |
||
341 | * TIME |
||
342 | * |
||
343 | * The TIME function returns a value that represents a particular time. |
||
344 | * |
||
345 | * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time |
||
346 | * format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. |
||
347 | * |
||
348 | * Excel Function: |
||
349 | * TIME(hour,minute,second) |
||
350 | * |
||
351 | * @category Date/Time Functions |
||
352 | * @param int $hour A number from 0 (zero) to 32767 representing the hour. |
||
353 | * Any value greater than 23 will be divided by 24 and the remainder |
||
354 | * will be treated as the hour value. For example, TIME(27,0,0) = |
||
355 | * TIME(3,0,0) = .125 or 3:00 AM. |
||
356 | * @param int $minute A number from 0 to 32767 representing the minute. |
||
357 | * Any value greater than 59 will be converted to hours and minutes. |
||
358 | * For example, TIME(0,750,0) = TIME(12,30,0) = .520833 or 12:30 PM. |
||
359 | * @param int $second A number from 0 to 32767 representing the second. |
||
360 | * Any value greater than 59 will be converted to hours, minutes, |
||
361 | * and seconds. For example, TIME(0,0,2000) = TIME(0,33,22) = .023148 |
||
362 | * or 12:33:20 AM |
||
363 | * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
||
364 | * depending on the value of the ReturnDateType flag |
||
365 | */ |
||
366 | 24 | public static function TIME($hour = 0, $minute = 0, $second = 0) |
|
367 | { |
||
368 | 24 | $hour = Functions::flattenSingleValue($hour); |
|
369 | 24 | $minute = Functions::flattenSingleValue($minute); |
|
370 | 24 | $second = Functions::flattenSingleValue($second); |
|
371 | |||
372 | 24 | if ($hour == '') { |
|
373 | $hour = 0; |
||
374 | } |
||
375 | 24 | if ($minute == '') { |
|
376 | 5 | $minute = 0; |
|
377 | } |
||
378 | 24 | if ($second == '') { |
|
379 | 5 | $second = 0; |
|
380 | } |
||
381 | |||
382 | 24 | if ((!is_numeric($hour)) || (!is_numeric($minute)) || (!is_numeric($second))) { |
|
383 | 1 | return Functions::VALUE(); |
|
384 | } |
||
385 | 23 | $hour = (integer) $hour; |
|
386 | 23 | $minute = (integer) $minute; |
|
387 | 23 | $second = (integer) $second; |
|
388 | |||
389 | 23 | View Code Duplication | if ($second < 0) { |
390 | 4 | $minute += floor($second / 60); |
|
391 | 4 | $second = 60 - abs($second % 60); |
|
392 | 4 | if ($second == 60) { |
|
393 | 4 | $second = 0; |
|
394 | } |
||
395 | 19 | } elseif ($second >= 60) { |
|
396 | 1 | $minute += floor($second / 60); |
|
397 | 1 | $second = $second % 60; |
|
398 | } |
||
399 | 23 | View Code Duplication | if ($minute < 0) { |
400 | 7 | $hour += floor($minute / 60); |
|
401 | 7 | $minute = 60 - abs($minute % 60); |
|
402 | 7 | if ($minute == 60) { |
|
403 | 7 | $minute = 0; |
|
404 | } |
||
405 | 16 | } elseif ($minute >= 60) { |
|
406 | 3 | $hour += floor($minute / 60); |
|
407 | 3 | $minute = $minute % 60; |
|
408 | } |
||
409 | |||
410 | 23 | if ($hour > 23) { |
|
411 | 1 | $hour = $hour % 24; |
|
412 | 22 | } elseif ($hour < 0) { |
|
413 | 2 | return Functions::NAN(); |
|
414 | } |
||
415 | |||
416 | // Execute function |
||
417 | 21 | switch (Functions::getReturnDateType()) { |
|
418 | 21 | case Functions::RETURNDATE_EXCEL: |
|
419 | 19 | $date = 0; |
|
420 | 19 | $calendar = \PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar(); |
|
421 | 19 | if ($calendar != \PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_WINDOWS_1900) { |
|
422 | $date = 1; |
||
423 | } |
||
424 | |||
425 | 19 | return (float) \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second); |
|
426 | 2 | case Functions::RETURNDATE_PHP_NUMERIC: |
|
427 | 1 | return (integer) \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp(\PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600 |
|
428 | 1 | case Functions::RETURNDATE_PHP_OBJECT: |
|
429 | 1 | $dayAdjust = 0; |
|
430 | 1 | View Code Duplication | if ($hour < 0) { |
431 | $dayAdjust = floor($hour / 24); |
||
432 | $hour = 24 - abs($hour % 24); |
||
433 | if ($hour == 24) { |
||
434 | $hour = 0; |
||
435 | } |
||
436 | 1 | } elseif ($hour >= 24) { |
|
437 | $dayAdjust = floor($hour / 24); |
||
438 | $hour = $hour % 24; |
||
439 | } |
||
440 | 1 | $phpDateObject = new \DateTime('1900-01-01 ' . $hour . ':' . $minute . ':' . $second); |
|
441 | 1 | if ($dayAdjust != 0) { |
|
442 | $phpDateObject->modify($dayAdjust . ' days'); |
||
443 | } |
||
444 | |||
445 | 1 | return $phpDateObject; |
|
446 | } |
||
447 | } |
||
448 | |||
449 | /** |
||
450 | * DATEVALUE |
||
451 | * |
||
452 | * Returns a value that represents a particular date. |
||
453 | * Use DATEVALUE to convert a date represented by a text string to an Excel or PHP date/time stamp |
||
454 | * value. |
||
455 | * |
||
456 | * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date |
||
457 | * format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. |
||
458 | * |
||
459 | * Excel Function: |
||
460 | * DATEVALUE(dateValue) |
||
461 | * |
||
462 | * @category Date/Time Functions |
||
463 | * @param string $dateValue Text that represents a date in a Microsoft Excel date format. |
||
464 | * For example, "1/30/2008" or "30-Jan-2008" are text strings within |
||
465 | * quotation marks that represent dates. Using the default date |
||
466 | * system in Excel for Windows, date_text must represent a date from |
||
467 | * January 1, 1900, to December 31, 9999. Using the default date |
||
468 | * system in Excel for the Macintosh, date_text must represent a date |
||
469 | * from January 1, 1904, to December 31, 9999. DATEVALUE returns the |
||
470 | * #VALUE! error value if date_text is out of this range. |
||
471 | * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
||
472 | * depending on the value of the ReturnDateType flag |
||
473 | */ |
||
474 | 422 | public static function DATEVALUE($dateValue = 1) |
|
583 | |||
584 | /** |
||
585 | * TIMEVALUE |
||
586 | * |
||
587 | * Returns a value that represents a particular time. |
||
588 | * Use TIMEVALUE to convert a time represented by a text string to an Excel or PHP date/time stamp |
||
589 | * value. |
||
590 | * |
||
591 | * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time |
||
592 | * format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. |
||
593 | * |
||
594 | * Excel Function: |
||
595 | * TIMEVALUE(timeValue) |
||
596 | * |
||
597 | * @category Date/Time Functions |
||
598 | * @param string $timeValue A text string that represents a time in any one of the Microsoft |
||
599 | * Excel time formats; for example, "6:45 PM" and "18:45" text strings |
||
600 | * within quotation marks that represent time. |
||
601 | * Date information in time_text is ignored. |
||
602 | * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
||
603 | * depending on the value of the ReturnDateType flag |
||
604 | */ |
||
605 | 30 | public static function TIMEVALUE($timeValue) |
|
643 | |||
644 | /** |
||
645 | * DATEDIF |
||
646 | * |
||
647 | * @param mixed $startDate Excel date serial value, PHP date/time stamp, PHP DateTime object |
||
648 | * or a standard date string |
||
649 | * @param mixed $endDate Excel date serial value, PHP date/time stamp, PHP DateTime object |
||
650 | * or a standard date string |
||
651 | * @param string $unit |
||
652 | * @return int Interval between the dates |
||
653 | */ |
||
654 | 149 | public static function DATEDIF($startDate = 0, $endDate = 0, $unit = 'D') |
|
759 | |||
760 | /** |
||
761 | * DAYS360 |
||
762 | * |
||
763 | * Returns the number of days between two dates based on a 360-day year (twelve 30-day months), |
||
764 | * which is used in some accounting calculations. Use this function to help compute payments if |
||
765 | * your accounting system is based on twelve 30-day months. |
||
766 | * |
||
767 | * Excel Function: |
||
768 | * DAYS360(startDate,endDate[,method]) |
||
769 | * |
||
770 | * @category Date/Time Functions |
||
771 | * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), |
||
772 | * PHP DateTime object, or a standard date string |
||
773 | * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer), |
||
774 | * PHP DateTime object, or a standard date string |
||
775 | * @param bool $method US or European Method |
||
776 | * FALSE or omitted: U.S. (NASD) method. If the starting date is |
||
777 | * the last day of a month, it becomes equal to the 30th of the |
||
778 | * same month. If the ending date is the last day of a month and |
||
779 | * the starting date is earlier than the 30th of a month, the |
||
780 | * ending date becomes equal to the 1st of the next month; |
||
781 | * otherwise the ending date becomes equal to the 30th of the |
||
782 | * same month. |
||
783 | * TRUE: European method. Starting dates and ending dates that |
||
784 | * occur on the 31st of a month become equal to the 30th of the |
||
785 | * same month. |
||
786 | * @return int Number of days between start date and end date |
||
787 | */ |
||
788 | 72 | public static function DAYS360($startDate = 0, $endDate = 0, $method = false) |
|
817 | |||
818 | /** |
||
819 | * YEARFRAC |
||
820 | * |
||
821 | * Calculates the fraction of the year represented by the number of whole days between two dates |
||
822 | * (the start_date and the end_date). |
||
823 | * Use the YEARFRAC worksheet function to identify the proportion of a whole year's benefits or |
||
824 | * obligations to assign to a specific term. |
||
825 | * |
||
826 | * Excel Function: |
||
827 | * YEARFRAC(startDate,endDate[,method]) |
||
828 | * |
||
829 | * @category Date/Time Functions |
||
830 | * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), |
||
831 | * PHP DateTime object, or a standard date string |
||
832 | * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer), |
||
833 | * PHP DateTime object, or a standard date string |
||
834 | * @param int $method Method used for the calculation |
||
835 | * 0 or omitted US (NASD) 30/360 |
||
836 | * 1 Actual/actual |
||
837 | * 2 Actual/360 |
||
838 | * 3 Actual/365 |
||
839 | * 4 European 30/360 |
||
840 | * @return float fraction of the year |
||
841 | */ |
||
842 | 89 | public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0) |
|
915 | |||
916 | /** |
||
917 | * NETWORKDAYS |
||
918 | * |
||
919 | * Returns the number of whole working days between start_date and end_date. Working days |
||
920 | * exclude weekends and any dates identified in holidays. |
||
921 | * Use NETWORKDAYS to calculate employee benefits that accrue based on the number of days |
||
922 | * worked during a specific term. |
||
923 | * |
||
924 | * Excel Function: |
||
925 | * NETWORKDAYS(startDate,endDate[,holidays[,holiday[,...]]]) |
||
926 | * |
||
927 | * @category Date/Time Functions |
||
928 | * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), |
||
929 | * PHP DateTime object, or a standard date string |
||
930 | * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer), |
||
931 | * PHP DateTime object, or a standard date string |
||
932 | * @return int Interval between the dates |
||
933 | */ |
||
934 | 18 | public static function NETWORKDAYS($startDate, $endDate) |
|
995 | |||
996 | /** |
||
997 | * WORKDAY |
||
998 | * |
||
999 | * Returns the date that is the indicated number of working days before or after a date (the |
||
1000 | * starting date). Working days exclude weekends and any dates identified as holidays. |
||
1001 | * Use WORKDAY to exclude weekends or holidays when you calculate invoice due dates, expected |
||
1002 | * delivery times, or the number of days of work performed. |
||
1003 | * |
||
1004 | * Excel Function: |
||
1005 | * WORKDAY(startDate,endDays[,holidays[,holiday[,...]]]) |
||
1006 | * |
||
1007 | * @category Date/Time Functions |
||
1008 | * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer), |
||
1009 | * PHP DateTime object, or a standard date string |
||
1010 | * @param int $endDays The number of nonweekend and nonholiday days before or after |
||
1011 | * startDate. A positive value for days yields a future date; a |
||
1012 | * negative value yields a past date. |
||
1013 | * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
||
1014 | * depending on the value of the ReturnDateType flag |
||
1015 | */ |
||
1016 | 13 | public static function WORKDAY($startDate, $endDays) |
|
1106 | |||
1107 | /** |
||
1108 | * DAYOFMONTH |
||
1109 | * |
||
1110 | * Returns the day of the month, for a specified date. The day is given as an integer |
||
1111 | * ranging from 1 to 31. |
||
1112 | * |
||
1113 | * Excel Function: |
||
1114 | * DAY(dateValue) |
||
1115 | * |
||
1116 | * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), |
||
1117 | * PHP DateTime object, or a standard date string |
||
1118 | * @return int Day of the month |
||
1119 | */ |
||
1120 | 17 | public static function DAYOFMONTH($dateValue = 1) |
|
1139 | |||
1140 | /** |
||
1141 | * WEEKDAY |
||
1142 | * |
||
1143 | * Returns the day of the week for a specified date. The day is given as an integer |
||
1144 | * ranging from 0 to 7 (dependent on the requested style). |
||
1145 | * |
||
1146 | * Excel Function: |
||
1147 | * WEEKDAY(dateValue[,style]) |
||
1148 | * |
||
1149 | * @param int $dateValue Excel date serial value (float), PHP date timestamp (integer), |
||
1150 | * PHP DateTime object, or a standard date string |
||
1151 | * @param int $style A number that determines the type of return value |
||
1152 | * 1 or omitted Numbers 1 (Sunday) through 7 (Saturday). |
||
1153 | * 2 Numbers 1 (Monday) through 7 (Sunday). |
||
1154 | * 3 Numbers 0 (Monday) through 6 (Sunday). |
||
1155 | * @return int Day of the week value |
||
1156 | */ |
||
1157 | 57 | public static function WEEKDAY($dateValue = 1, $style = 1) |
|
1211 | |||
1212 | /** |
||
1213 | * WEEKNUM |
||
1214 | * |
||
1215 | * Returns the week of the year for a specified date. |
||
1216 | * The WEEKNUM function considers the week containing January 1 to be the first week of the year. |
||
1217 | * However, there is a European standard that defines the first week as the one with the majority |
||
1218 | * of days (four or more) falling in the new year. This means that for years in which there are |
||
1219 | * three days or less in the first week of January, the WEEKNUM function returns week numbers |
||
1220 | * that are incorrect according to the European standard. |
||
1221 | * |
||
1222 | * Excel Function: |
||
1223 | * WEEKNUM(dateValue[,style]) |
||
1224 | * |
||
1225 | * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), |
||
1226 | * PHP DateTime object, or a standard date string |
||
1227 | * @param int $method Week begins on Sunday or Monday |
||
1228 | * 1 or omitted Week begins on Sunday. |
||
1229 | * 2 Week begins on Monday. |
||
1230 | * @return int Week Number |
||
1231 | */ |
||
1232 | 15 | public static function WEEKNUM($dateValue = 1, $method = 1) |
|
1267 | |||
1268 | /** |
||
1269 | * MONTHOFYEAR |
||
1270 | * |
||
1271 | * Returns the month of a date represented by a serial number. |
||
1272 | * The month is given as an integer, ranging from 1 (January) to 12 (December). |
||
1273 | * |
||
1274 | * Excel Function: |
||
1275 | * MONTH(dateValue) |
||
1276 | * |
||
1277 | * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), |
||
1278 | * PHP DateTime object, or a standard date string |
||
1279 | * @return int Month of the year |
||
1280 | */ |
||
1281 | 21 | View Code Duplication | public static function MONTHOFYEAR($dateValue = 1) |
1299 | |||
1300 | /** |
||
1301 | * YEAR |
||
1302 | * |
||
1303 | * Returns the year corresponding to a date. |
||
1304 | * The year is returned as an integer in the range 1900-9999. |
||
1305 | * |
||
1306 | * Excel Function: |
||
1307 | * YEAR(dateValue) |
||
1308 | * |
||
1309 | * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), |
||
1310 | * PHP DateTime object, or a standard date string |
||
1311 | * @return int Year |
||
1312 | */ |
||
1313 | 33 | View Code Duplication | public static function YEAR($dateValue = 1) |
1330 | |||
1331 | /** |
||
1332 | * HOUROFDAY |
||
1333 | * |
||
1334 | * Returns the hour of a time value. |
||
1335 | * The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.). |
||
1336 | * |
||
1337 | * Excel Function: |
||
1338 | * HOUR(timeValue) |
||
1339 | * |
||
1340 | * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer), |
||
1341 | * PHP DateTime object, or a standard time string |
||
1342 | * @return int Hour |
||
1343 | */ |
||
1344 | 12 | View Code Duplication | public static function HOUROFDAY($timeValue = 0) |
1370 | |||
1371 | /** |
||
1372 | * MINUTE |
||
1373 | * |
||
1374 | * Returns the minutes of a time value. |
||
1375 | * The minute is given as an integer, ranging from 0 to 59. |
||
1376 | * |
||
1377 | * Excel Function: |
||
1378 | * MINUTE(timeValue) |
||
1379 | * |
||
1380 | * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer), |
||
1381 | * PHP DateTime object, or a standard time string |
||
1382 | * @return int Minute |
||
1383 | */ |
||
1384 | 12 | View Code Duplication | public static function MINUTE($timeValue = 0) |
1410 | |||
1411 | /** |
||
1412 | * SECOND |
||
1413 | * |
||
1414 | * Returns the seconds of a time value. |
||
1415 | * The second is given as an integer in the range 0 (zero) to 59. |
||
1416 | * |
||
1417 | * Excel Function: |
||
1418 | * SECOND(timeValue) |
||
1419 | * |
||
1420 | * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer), |
||
1421 | * PHP DateTime object, or a standard time string |
||
1422 | * @return int Second |
||
1423 | */ |
||
1424 | 12 | View Code Duplication | public static function SECOND($timeValue = 0) |
1450 | |||
1451 | /** |
||
1452 | * EDATE |
||
1453 | * |
||
1454 | * Returns the serial number that represents the date that is the indicated number of months |
||
1455 | * before or after a specified date (the start_date). |
||
1456 | * Use EDATE to calculate maturity dates or due dates that fall on the same day of the month |
||
1457 | * as the date of issue. |
||
1458 | * |
||
1459 | * Excel Function: |
||
1460 | * EDATE(dateValue,adjustmentMonths) |
||
1461 | * |
||
1462 | * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), |
||
1463 | * PHP DateTime object, or a standard date string |
||
1464 | * @param int $adjustmentMonths The number of months before or after start_date. |
||
1465 | * A positive value for months yields a future date; |
||
1466 | * a negative value yields a past date. |
||
1467 | * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
||
1468 | * depending on the value of the ReturnDateType flag |
||
1469 | */ |
||
1470 | 17 | public static function EDATE($dateValue = 1, $adjustmentMonths = 0) |
|
1496 | |||
1497 | /** |
||
1498 | * EOMONTH |
||
1499 | * |
||
1500 | * Returns the date value for the last day of the month that is the indicated number of months |
||
1501 | * before or after start_date. |
||
1502 | * Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month. |
||
1503 | * |
||
1504 | * Excel Function: |
||
1505 | * EOMONTH(dateValue,adjustmentMonths) |
||
1506 | * |
||
1507 | * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), |
||
1508 | * PHP DateTime object, or a standard date string |
||
1509 | * @param int $adjustmentMonths The number of months before or after start_date. |
||
1510 | * A positive value for months yields a future date; |
||
1511 | * a negative value yields a past date. |
||
1512 | * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
||
1513 | * depending on the value of the ReturnDateType flag |
||
1514 | */ |
||
1515 | 19 | public static function EOMONTH($dateValue = 1, $adjustmentMonths = 0) |
|
1544 | } |
||
1545 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.