/** * Returns a cell's PHP Date value, associated to the given timestamp. * NOTE: The timestamp is a float representing the number of days since January 1st, 1900. * * @param float $nodeValue * @param int $cellStyleId 0 being the default style * @return \DateTime|string|null The value associated with the cell or NULL if invalid date value */ protected function formatExcelTimestampValueAsDateValue($nodeValue, $cellStyleId) { // Do not use any unix timestamps for calculation to prevent // issues with numbers exceeding 2^31. $secondsRemainder = fmod($nodeValue, 1) * self::NUM_SECONDS_IN_ONE_DAY; $secondsRemainder = round($secondsRemainder, 0); try { $dateObj = \DateTime::createFromFormat('|Y-m-d', '1899-12-31'); $dateObj->modify('+' . intval($nodeValue) . 'days'); $dateObj->modify('+' . $secondsRemainder . 'seconds'); if ($this->shouldFormatDates) { $styleNumberFormat = $this->styleHelper->getNumberFormat($cellStyleId); $phpDateFormat = DateFormatHelper::toPHPDateFormat($styleNumberFormat); return $dateObj->format($phpDateFormat); } else { return $dateObj; } } catch (\Exception $e) { return null; } }