| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; |
| 4 |
|
| 5 |
use DateTime; |
| 6 |
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; |
| 7 |
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception; |
| 8 |
|
| 9 |
class Month |
| 10 |
{ |
| 11 |
use ArrayEnabled; |
| 12 |
|
| 13 |
/** |
| 14 |
* EDATE. |
| 15 |
* |
| 16 |
* Returns the serial number that represents the date that is the indicated number of months |
| 17 |
* before or after a specified date (the start_date). |
| 18 |
* Use EDATE to calculate maturity dates or due dates that fall on the same day of the month |
| 19 |
* as the date of issue. |
| 20 |
* |
| 21 |
* Excel Function: |
| 22 |
* EDATE(dateValue,adjustmentMonths) |
| 23 |
* |
| 24 |
* @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), |
| 25 |
* PHP DateTime object, or a standard date string |
| 26 |
* Or can be an array of date values |
| 27 |
* @param array<mixed>|int $adjustmentMonths The number of months before or after start_date. |
| 28 |
* A positive value for months yields a future date; |
| 29 |
* a negative value yields a past date. |
| 30 |
* Or can be an array of adjustment values |
| 31 |
* |
| 32 |
* @return array<mixed>|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
| 33 |
* depending on the value of the ReturnDateType flag |
| 34 |
* If an array of values is passed as the argument, then the returned result will also be an array |
| 35 |
* with the same dimensions |
| 36 |
*/ |
| 37 |
public static function adjust($dateValue, $adjustmentMonths) |
| 38 |
{ |
| 39 |
if (is_array($dateValue) || is_array($adjustmentMonths)) { |
| 40 |
return self::evaluateArrayArguments([self::class, __FUNCTION__], $dateValue, $adjustmentMonths); |
| 41 |
} |
| 42 |
|
| 43 |
try { |
| 44 |
$dateValue = Helpers::getDateValue($dateValue, false); |
| 45 |
$adjustmentMonths = Helpers::validateNumericNull($adjustmentMonths); |
| 46 |
} catch (Exception $e) { |
| 47 |
return $e->getMessage(); |
| 48 |
} |
| 49 |
$dateValue = floor($dateValue); |
| 50 |
$adjustmentMonths = floor($adjustmentMonths); |
| 51 |
|
| 52 |
// Execute function |
| 53 |
$PHPDateObject = Helpers::adjustDateByMonths($dateValue, $adjustmentMonths); |
| 54 |
|
| 55 |
return Helpers::returnIn3FormatsObject($PHPDateObject); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* EOMONTH. |
| 60 |
* |
| 61 |
* Returns the date value for the last day of the month that is the indicated number of months |
| 62 |
* before or after start_date. |
| 63 |
* Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month. |
| 64 |
* |
| 65 |
* Excel Function: |
| 66 |
* EOMONTH(dateValue,adjustmentMonths) |
| 67 |
* |
| 68 |
* @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer), |
| 69 |
* PHP DateTime object, or a standard date string |
| 70 |
* Or can be an array of date values |
| 71 |
* @param array<mixed>|int $adjustmentMonths The number of months before or after start_date. |
| 72 |
* A positive value for months yields a future date; |
| 73 |
* a negative value yields a past date. |
| 74 |
* Or can be an array of adjustment values |
| 75 |
* |
| 76 |
* @return array<mixed>|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
| 77 |
* depending on the value of the ReturnDateType flag |
| 78 |
* If an array of values is passed as the argument, then the returned result will also be an array |
| 79 |
* with the same dimensions |
| 80 |
*/ |
| 81 |
public static function lastDay($dateValue, $adjustmentMonths) |
| 82 |
{ |
| 83 |
if (is_array($dateValue) || is_array($adjustmentMonths)) { |
| 84 |
return self::evaluateArrayArguments([self::class, __FUNCTION__], $dateValue, $adjustmentMonths); |
| 85 |
} |
| 86 |
|
| 87 |
try { |
| 88 |
$dateValue = Helpers::getDateValue($dateValue, false); |
| 89 |
$adjustmentMonths = Helpers::validateNumericNull($adjustmentMonths); |
| 90 |
} catch (Exception $e) { |
| 91 |
return $e->getMessage(); |
| 92 |
} |
| 93 |
$dateValue = floor($dateValue); |
| 94 |
$adjustmentMonths = floor($adjustmentMonths); |
| 95 |
|
| 96 |
// Execute function |
| 97 |
$PHPDateObject = Helpers::adjustDateByMonths($dateValue, $adjustmentMonths + 1); |
| 98 |
$adjustDays = (int) $PHPDateObject->format('d'); |
| 99 |
$adjustDaysString = '-' . $adjustDays . ' days'; |
| 100 |
$PHPDateObject->modify($adjustDaysString); |
| 101 |
|
| 102 |
return Helpers::returnIn3FormatsObject($PHPDateObject); |
| 103 |
} |
| 104 |
} |
| 105 |
|