← All changes
|
libraries/vendor/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
+23
-21
3.3.1
→
3.4
View file →
| @@ -30,12 +30,12 @@ | ||
| 30 | 30 | * |
| 31 | 31 | * @return float Excel date/time serial value |
| 32 | 32 | * @param mixed $dateValue |
| 33 | 33 | */ |
| 34 | - public static function getDateValue($dateValue, bool $allowBool = true): float | |
| 34 | + public static function getDateValue($dateValue, bool $allowBool = true, ?int $calendar = null): float | |
| 35 | 35 | { |
| 36 | 36 | if (is_object($dateValue)) { |
| 37 | - $retval = SharedDateHelper::PHPToExcel($dateValue); | |
| 37 | + $retval = SharedDateHelper::PHPToExcel($dateValue, $calendar); | |
| 38 | 38 | if (is_bool($retval)) { |
| 39 | 39 | throw new Exception(ExcelError::VALUE()); |
| 40 | 40 | } |
| 41 | 41 | |
| @@ -41,9 +41,9 @@ | ||
| 41 | 41 | |
| 42 | 42 | return $retval; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - self::nullFalseTrueToNumber($dateValue, $allowBool); | |
| 45 | + self::nullFalseTrueToNumber($dateValue, $allowBool, $calendar); | |
| 46 | 46 | if (!is_numeric($dateValue)) { |
| 47 | 47 | $saveReturnDateType = Functions::getReturnDateType(); |
| 48 | 48 | Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); |
| 49 | 49 | if (is_string($dateValue)) { |
| @@ -58,9 +58,9 @@ | ||
| 58 | 58 | throw new Exception(ExcelError::NAN()); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | try { |
| 62 | - SharedDateHelper::excelToDateTimeObject((float) $dateValue); | |
| 62 | + SharedDateHelper::excelToDateTimeObject((float) $dateValue, null, $calendar); | |
| 63 | 63 | } catch (Throwable $exception) { |
| 64 | 64 | throw new Exception(ExcelError::NAN()); |
| 65 | 65 | } |
| 66 | 66 | |
| @@ -87,12 +87,12 @@ | ||
| 87 | 87 | * Adjust date by given months. |
| 88 | 88 | * |
| 89 | 89 | * @param float|int $dateValue date to be adjusted |
| 90 | 90 | */ |
| 91 | - public static function adjustDateByMonths($dateValue = 0, float $adjustmentMonths = 0): DateTime | |
| 91 | + public static function adjustDateByMonths($dateValue = 0, float $adjustmentMonths = 0, ?int $calendar = null): DateTime | |
| 92 | 92 | { |
| 93 | 93 | // Execute function |
| 94 | - $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue); | |
| 94 | + $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue, null, $calendar); | |
| 95 | 95 | $oMonth = (int) $PHPDateObject->format('m'); |
| 96 | 96 | $oYear = (int) $PHPDateObject->format('Y'); |
| 97 | 97 | |
| 98 | 98 | $adjustmentMonthsString = (string) $adjustmentMonths; |
| @@ -144,9 +144,9 @@ | ||
| 144 | 144 | * |
| 145 | 145 | * @param array{year: int, month: int, day: int, hour: int, minute: int, second: int} $dateArray |
| 146 | 146 | * @return \DateTime|float|int |
| 147 | 147 | */ |
| 148 | - public static function returnIn3FormatsArray(array $dateArray, bool $noFrac = false) | |
| 148 | + public static function returnIn3FormatsArray(array $dateArray, bool $noFrac = false, ?int $calendar = null) | |
| 149 | 149 | { |
| 150 | 150 | $retType = Functions::getReturnDateType(); |
| 151 | 151 | if ($retType === Functions::RETURNDATE_PHP_DATETIME_OBJECT) { |
| 152 | 152 | return new DateTime( |
| @@ -164,9 +164,10 @@ | ||
| 164 | 164 | $dateArray['month'], |
| 165 | 165 | $dateArray['day'], |
| 166 | 166 | $dateArray['hour'], |
| 167 | 167 | $dateArray['minute'], |
| 168 | - $dateArray['second'] | |
| 168 | + $dateArray['second'], | |
| 169 | + $calendar | |
| 169 | 170 | ); |
| 170 | 171 | if ($retType === Functions::RETURNDATE_EXCEL) { |
| 171 | 172 | return $noFrac ? floor($excelDateValue) : $excelDateValue; |
| 172 | 173 | } |
| @@ -171,9 +172,9 @@ | ||
| 171 | 172 | return $noFrac ? floor($excelDateValue) : $excelDateValue; |
| 172 | 173 | } |
| 173 | 174 | // RETURNDATE_UNIX_TIMESTAMP) |
| 174 | 175 | |
| 175 | - return SharedDateHelper::excelToTimestamp($excelDateValue); | |
| 176 | + return SharedDateHelper::excelToTimestamp($excelDateValue, null, $calendar); | |
| 176 | 177 | } |
| 177 | 178 | |
| 178 | 179 | /** |
| 179 | 180 | * Return result in one of three formats. |
| @@ -178,9 +179,9 @@ | ||
| 178 | 179 | /** |
| 179 | 180 | * Return result in one of three formats. |
| 180 | 181 | * @return float|int|\DateTime |
| 181 | 182 | */ |
| 182 | - public static function returnIn3FormatsFloat(float $excelDateValue) | |
| 183 | + public static function returnIn3FormatsFloat(float $excelDateValue, ?int $calendar = null) | |
| 183 | 184 | { |
| 184 | 185 | $retType = Functions::getReturnDateType(); |
| 185 | 186 | if ($retType === Functions::RETURNDATE_EXCEL) { |
| 186 | 187 | return $excelDateValue; |
| @@ -185,13 +186,13 @@ | ||
| 185 | 186 | if ($retType === Functions::RETURNDATE_EXCEL) { |
| 186 | 187 | return $excelDateValue; |
| 187 | 188 | } |
| 188 | 189 | if ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) { |
| 189 | - return SharedDateHelper::excelToTimestamp($excelDateValue); | |
| 190 | + return SharedDateHelper::excelToTimestamp($excelDateValue, null, $calendar); | |
| 190 | 191 | } |
| 191 | 192 | // RETURNDATE_PHP_DATETIME_OBJECT |
| 192 | 193 | |
| 193 | - return SharedDateHelper::excelToDateTimeObject($excelDateValue); | |
| 194 | + return SharedDateHelper::excelToDateTimeObject($excelDateValue, null, $calendar); | |
| 194 | 195 | } |
| 195 | 196 | |
| 196 | 197 | /** |
| 197 | 198 | * Return result in one of three formats. |
| @@ -196,9 +197,9 @@ | ||
| 196 | 197 | /** |
| 197 | 198 | * Return result in one of three formats. |
| 198 | 199 | * @return \DateTime|float|int |
| 199 | 200 | */ |
| 200 | - public static function returnIn3FormatsObject(DateTime $PHPDateObject) | |
| 201 | + public static function returnIn3FormatsObject(DateTime $PHPDateObject, ?int $calendar = null) | |
| 201 | 202 | { |
| 202 | 203 | $retType = Functions::getReturnDateType(); |
| 203 | 204 | if ($retType === Functions::RETURNDATE_PHP_DATETIME_OBJECT) { |
| 204 | 205 | return $PHPDateObject; |
| @@ -203,23 +204,24 @@ | ||
| 203 | 204 | if ($retType === Functions::RETURNDATE_PHP_DATETIME_OBJECT) { |
| 204 | 205 | return $PHPDateObject; |
| 205 | 206 | } |
| 206 | 207 | if ($retType === Functions::RETURNDATE_EXCEL) { |
| 207 | - return (float) SharedDateHelper::PHPToExcel($PHPDateObject); | |
| 208 | + return (float) SharedDateHelper::PHPToExcel($PHPDateObject, $calendar); | |
| 208 | 209 | } |
| 209 | 210 | // RETURNDATE_UNIX_TIMESTAMP |
| 210 | - $stamp = SharedDateHelper::PHPToExcel($PHPDateObject); | |
| 211 | + $stamp = SharedDateHelper::PHPToExcel($PHPDateObject, $calendar); | |
| 211 | 212 | $stamp = is_bool($stamp) ? ((int) $stamp) : $stamp; |
| 212 | 213 | |
| 213 | - return SharedDateHelper::excelToTimestamp($stamp); | |
| 214 | + return SharedDateHelper::excelToTimestamp($stamp, null, $calendar); | |
| 214 | 215 | } |
| 215 | 216 | |
| 216 | - private static function baseDate(): int | |
| 217 | + private static function baseDate(?int $calendar): int | |
| 217 | 218 | { |
| 218 | 219 | if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) { |
| 219 | 220 | return 0; |
| 220 | 221 | } |
| 221 | - if (SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_MAC_1904) { | |
| 222 | + $calendar ??= SharedDateHelper::getExcelCalendar(); | |
| 223 | + if ($calendar === SharedDateHelper::CALENDAR_MAC_1904) { | |
| 222 | 224 | return 0; |
| 223 | 225 | } |
| 224 | 226 | |
| 225 | 227 | return 1; |
| @@ -228,12 +230,12 @@ | ||
| 228 | 230 | /** |
| 229 | 231 | * Many functions accept null/false/true argument treated as 0/0/1. |
| 230 | 232 | * @param mixed $number |
| 231 | 233 | */ |
| 232 | - public static function nullFalseTrueToNumber(&$number, bool $allowBool = true): void | |
| 234 | + public static function nullFalseTrueToNumber(&$number, bool $allowBool = true, ?int $calendar = null): void | |
| 233 | 235 | { |
| 234 | 236 | $number = Functions::flattenSingleValue($number); |
| 235 | - $nullVal = self::baseDate(); | |
| 237 | + $nullVal = self::baseDate($calendar); | |
| 236 | 238 | if ($number === null) { |
| 237 | 239 | $number = $nullVal; |
| 238 | 240 | } elseif ($allowBool && is_bool($number)) { |
| 239 | 241 | $number = $nullVal + (int) $number; |
| @@ -241,9 +243,9 @@ | ||
| 241 | 243 | } |
| 242 | 244 | |
| 243 | 245 | /** |
| 244 | 246 | * Many functions accept null argument treated as 0. |
| 245 | - * @return float|int | |
| 247 | + * @return int|float | |
| 246 | 248 | * @param mixed $number |
| 247 | 249 | */ |
| 248 | 250 | public static function validateNumericNull($number) |
| 249 | 251 | { |