76 ($baseDate == self::CALENDAR_WINDOWS_1900) ||
77 ($baseDate == self::CALENDAR_MAC_1904)
79 self::$excelCalendar = $baseDate;
94 return self::$excelCalendar;
122 return self::$defaultTimeZone ??
new DateTimeZone(
'UTC');
130 return self::$defaultTimeZone ??
new DateTimeZone(date_default_timezone_get());
138 return self::$defaultTimeZone;
153 if (in_array(
$timeZone, DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC))) {
174 if ($excelTimestamp < 1 && self::$excelCalendar === self::CALENDAR_WINDOWS_1900) {
179 if (self::$excelCalendar == self::CALENDAR_WINDOWS_1900) {
190 $days = floor($excelTimestamp);
191 $partDay = $excelTimestamp - $days;
192 $hours = floor($partDay * 24);
193 $partDay = $partDay * 24 - $hours;
194 $minutes = floor($partDay * 60);
195 $partDay = $partDay * 60 - $minutes;
196 $seconds = round($partDay * 60);
201 $interval = $days .
' days';
203 return $baseDate->modify($interval)
204 ->setTime((
int) $hours, (
int) $minutes, (
int) $seconds);
219 return (
int) self::excelToDateTimeObject($excelTimestamp,
$timeZone)
234 return self::dateTimeToExcel($dateValue);
235 } elseif (is_numeric($dateValue)) {
236 return self::timestampToExcel($dateValue);
237 } elseif (is_string($dateValue)) {
238 return self::stringToExcel($dateValue);
253 return self::formattedPHPToExcel(
254 (
int) $dateValue->format(
'Y'),
255 (int) $dateValue->format(
'm'),
256 (int) $dateValue->format(
'd'),
257 (int) $dateValue->format(
'H'),
258 (int) $dateValue->format(
'i'),
259 (int) $dateValue->format(
's')
272 if (!is_numeric($dateValue)) {
276 return self::dateTimeToExcel(
new DateTime(
'@' . $dateValue));
293 if (self::$excelCalendar == self::CALENDAR_WINDOWS_1900) {
298 $excel1900isLeapYear =
true;
299 if (($year == 1900) && ($month <= 2)) {
300 $excel1900isLeapYear =
false;
302 $myexcelBaseDate = 2415020;
304 $myexcelBaseDate = 2416481;
305 $excel1900isLeapYear =
false;
317 $century = (int) substr($year, 0, 2);
318 $decade = (int) substr($year, 2, 2);
319 $excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myexcelBaseDate + $excel1900isLeapYear;
321 $excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;
323 return (
float) $excelDate + $excelTime;
334 self::isDateTimeFormat(
348 return self::isDateTimeFormatCode($pFormat->
getFormatCode());
366 if (preg_match(
'/[0#]E[+-]0/i', $pFormatCode)) {
372 switch ($pFormatCode) {
400 if ((substr($pFormatCode, 0, 1) ==
'_') || (substr($pFormatCode, 0, 2) ==
'0 ')) {
405 if (\strpos($pFormatCode,
'-00000') !==
false) {
409 if (preg_match(
'/(^|\])[^\[]*[' . self::$possibleDateFormatCharacters .
']/i', $pFormatCode)) {
412 if (strpos($pFormatCode,
'"') !==
false) {
414 foreach (explode(
'"', $pFormatCode) as $subVal) {
417 ($segMatcher = !$segMatcher) &&
418 (preg_match(
'/(^|\])[^\[]*[' . self::$possibleDateFormatCharacters .
']/i', $subVal))
443 if (strlen($dateValue) < 2) {
446 if (!preg_match(
'/^(\d{1,4}[ \.\/\-][A-Z]{3,9}([ \.\/\-]\d{1,4})?|[A-Z]{3,9}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?|\d{1,4}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?)( \d{1,2}:\d{1,2}(:\d{1,2})?)?$/iu', $dateValue)) {
450 $dateValueNew = DateTimeExcel\DateValue::fromString($dateValue);
456 if (strpos($dateValue,
':') !==
false) {
457 $timeValue = DateTimeExcel\TimeValue::fromString($dateValue);
461 $dateValueNew += $timeValue;
464 return $dateValueNew;
477 foreach (self::$monthNames as $shortMonthName => $longMonthName) {
478 if (($month === $longMonthName) || ($month === $shortMonthName)) {
496 $strippedDayValue = (str_replace(self::$numberSuffixes,
'', $day));
497 if (is_numeric($strippedDayValue)) {
498 return (
int) $strippedDayValue;
506 $dtobj = DateTime::createFromFormat(
'U', $date) ?:
new DateTime();
507 $dtobj->setTimeZone(
$timeZone ?? self::getDefaultOrLocalTimezone());
514 $dtobj = self::dateTimeFromTimestamp($date,
$timeZone);
516 return $dtobj->format($format);
getCoordinate()
Get cell coordinate.
static monthStringToNumber($month)
Converts a month name (either a long or a short name) to a month number.
static excelToDateTimeObject($excelTimestamp, $timeZone=null)
Convert a MS serialized datetime value from Excel to a PHP Date/Time object.
static getDefaultTimezone()
Return the Default timezone, or UTC if default not set.
static getDefaultTimezoneOrNull()
Return the Default timezone even if null.
static isDateTimeFormatCode($pFormatCode)
Is a given number format code a date/time?
static getDefaultOrLocalTimezone()
Return the Default timezone, or local timezone if default is not set.
const COMPATIBILITY_EXCEL
constants
static isDateTimeFormat(NumberFormat $pFormat)
Is a given number format a date/time?
static formattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0)
formattedPHPToExcel.
static dayStringToNumber($day)
Strips an ordinal from a numeric value.
static formattedDateTimeFromTimestamp(string $date, string $format, ?DateTimeZone $timeZone=null)
static dateTimeFromTimestamp(string $date, ?DateTimeZone $timeZone=null)
static setDefaultTimezone($timeZone)
Set the Default timezone to use for dates.
static timestampToExcel($dateValue)
Convert a Unix timestamp to an MS Excel serialized date/time value.
static PHPToExcel($dateValue)
Convert a date from PHP to an MS Excel serialized date/time value.
const CALENDAR_WINDOWS_1900
constants
static validateTimeZone($timeZone)
Validate a timezone.
static dateTimeToExcel(DateTimeInterface $dateValue)
Convert a PHP DateTime object to an MS Excel serialized date/time value.
static setExcelCalendar($baseDate)
Set the Excel calendar (Windows 1900 or Mac 1904).
getCalculatedValue($resetLog=true)
Get calculated cell value.
static excelToTimestamp($excelTimestamp, $timeZone=null)
Convert a MS serialized datetime value from Excel to a unix timestamp.
static $possibleDateFormatCharacters
static stringToExcel($dateValue)
Convert a date/time string to Excel time.
static isDateTime(Cell $pCell)
Is a given cell a date/time?
getWorksheet()
Get parent worksheet.
static getCompatibilityMode()
Return the current Compatibility Mode.
static getExcelCalendar()
Return the Excel calendar (Windows 1900 or Mac 1904).