← All changes
|
libraries/vendor/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php
+13
-3
3.3.3
→
3.4
View file →
| @@ -45,8 +45,18 @@ | ||
| 45 | 45 | if (is_array($dateValue)) { |
| 46 | 46 | return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $dateValue); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | + return self::fromString2($dateValue, null); | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * @return array<mixed>|DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, | |
| 54 | + * depending on the value of the ReturnDateType flag | |
| 55 | + * @param null|string|int|bool|float $dateValue | |
| 56 | + */ | |
| 57 | + public static function fromString2($dateValue, ?int $calendar = null) | |
| 58 | + { | |
| 49 | 59 | // try to parse as date iff there is at least one digit |
| 50 | 60 | if (is_string($dateValue) && preg_match('/\d/', $dateValue) !== 1) { |
| 51 | 61 | return ExcelError::VALUE(); |
| 52 | 62 | } |
| @@ -51,9 +61,9 @@ | ||
| 51 | 61 | return ExcelError::VALUE(); |
| 52 | 62 | } |
| 53 | 63 | |
| 54 | 64 | $dti = new DateTimeImmutable(); |
| 55 | - $baseYear = SharedDateHelper::getExcelCalendar(); | |
| 65 | + $baseYear = $calendar ?? SharedDateHelper::getExcelCalendar(); | |
| 56 | 66 | $dateValue = trim((string) $dateValue, '"'); |
| 57 | 67 | // Strip any ordinals because they're allowed in Excel (English only) |
| 58 | 68 | $dateValue = (string) preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue); |
| 59 | 69 | // Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany) |
| @@ -159,11 +169,11 @@ | ||
| 159 | 169 | $month = self::getInt($PHPDateArray, 'month'); |
| 160 | 170 | $day = self::getInt($PHPDateArray, 'day'); |
| 161 | 171 | $year = self::getInt($PHPDateArray, 'year'); |
| 162 | 172 | if (!checkdate($month, $day, $year)) { |
| 163 | - return ($year === 1900 && $month === 2 && $day === 29) ? Helpers::returnIn3FormatsFloat(60.0) : ExcelError::VALUE(); | |
| 173 | + return ($year === 1900 && $month === 2 && $day === 29) ? Helpers::returnIn3FormatsFloat(60.0, $baseYear) : ExcelError::VALUE(); | |
| 164 | 174 | } |
| 165 | - $retValue = Helpers::returnIn3FormatsArray($PHPDateArray, true); | |
| 175 | + $retValue = Helpers::returnIn3FormatsArray($PHPDateArray, true, $baseYear); | |
| 166 | 176 | } |
| 167 | 177 | |
| 168 | 178 | return $retValue; |
| 169 | 179 | } |