ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
PHPExcel_Shared_Date Class Reference
+ Collaboration diagram for PHPExcel_Shared_Date:

Static Public Member Functions

static setExcelCalendar ($baseDate)
 Set the Excel calendar (Windows 1900 or Mac 1904) More...
 
static getExcelCalendar ()
 Return the Excel calendar (Windows 1900 or Mac 1904) More...
 
static ExcelToPHP ($dateValue=0, $adjustToTimezone=FALSE, $timezone=NULL)
 Convert a date from Excel to PHP. More...
 
static ExcelToPHPObject ($dateValue=0)
 Convert a date from Excel to a PHP Date/Time object. More...
 
static PHPToExcel ($dateValue=0, $adjustToTimezone=FALSE, $timezone=NULL)
 Convert a date from PHP to Excel. More...
 
static FormattedPHPToExcel ($year, $month, $day, $hours=0, $minutes=0, $seconds=0)
 FormattedPHPToExcel. More...
 
static isDateTime (PHPExcel_Cell $pCell)
 Is a given cell a date/time? More...
 
static isDateTimeFormat (PHPExcel_Style_NumberFormat $pFormat)
 Is a given number format a date/time? More...
 
static isDateTimeFormatCode ($pFormatCode='')
 Is a given number format code a date/time? More...
 
static stringToExcel ($dateValue='')
 Convert a date/time string to Excel time. More...
 
static monthStringToNumber ($month)
 
static dayStringToNumber ($day)
 

Data Fields

const CALENDAR_WINDOWS_1900 = 1900
 constants More...
 
const CALENDAR_MAC_1904 = 1904
 

Static Public Attributes

static $_monthNames
 
static $_numberSuffixes
 

Static Protected Attributes

static $_excelBaseDate = self::CALENDAR_WINDOWS_1900
 

Static Private Attributes

static $possibleDateFormatCharacters = 'eymdHs'
 

Detailed Description

Definition at line 37 of file Date.php.

Member Function Documentation

◆ dayStringToNumber()

static PHPExcel_Shared_Date::dayStringToNumber (   $day)
static

Definition at line 385 of file Date.php.

Referenced by PHPExcel_Calculation_DateTime\DATE().

385  {
386  $strippedDayValue = (str_replace(self::$_numberSuffixes,'',$day));
387  if (is_numeric($strippedDayValue)) {
388  return $strippedDayValue;
389  }
390  return $day;
391  }
+ Here is the caller graph for this function:

◆ ExcelToPHP()

static PHPExcel_Shared_Date::ExcelToPHP (   $dateValue = 0,
  $adjustToTimezone = FALSE,
  $timezone = NULL 
)
static

Convert a date from Excel to PHP.

Parameters
long$dateValueExcel date/time value
boolean$adjustToTimezoneFlag indicating whether $dateValue should be treated as a UST timestamp, or adjusted to UST
string$timezoneThe timezone for finding the adjustment from UST
Returns
long PHP serialized date/time

Definition at line 120 of file Date.php.

Referenced by PHPExcel_Worksheet_AutoFilter\_filterTestInDateGroupSet(), PHPExcel_Worksheet_AutoFilter\_filterTestInPeriodDateSet(), PHPExcel_Calculation_DateTime\DATE(), PHPExcel_Calculation_DateTime\DATENOW(), PHPExcel_Calculation_DateTime\DATEVALUE(), PHPExcel_Calculation_DateTime\EDATE(), PHPExcel_Calculation_DateTime\EOMONTH(), PHPExcel_Calculation_DateTime\HOUROFDAY(), PHPExcel_Calculation_DateTime\MINUTEOFHOUR(), PHPExcel_Calculation_DateTime\SECONDOFMINUTE(), PHPExcel_Calculation_DateTime\TIME(), PHPExcel_Calculation_DateTime\TIMEVALUE(), and PHPExcel_Calculation_DateTime\WORKDAY().

120  {
121  if (self::$_excelBaseDate == self::CALENDAR_WINDOWS_1900) {
122  $my_excelBaseDate = 25569;
123  // Adjust for the spurious 29-Feb-1900 (Day 60)
124  if ($dateValue < 60) {
125  --$my_excelBaseDate;
126  }
127  } else {
128  $my_excelBaseDate = 24107;
129  }
130 
131  // Perform conversion
132  if ($dateValue >= 1) {
133  $utcDays = $dateValue - $my_excelBaseDate;
134  $returnValue = round($utcDays * 86400);
135  if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) {
136  $returnValue = (integer) $returnValue;
137  }
138  } else {
139  $hours = round($dateValue * 24);
140  $mins = round($dateValue * 1440) - round($hours * 60);
141  $secs = round($dateValue * 86400) - round($hours * 3600) - round($mins * 60);
142  $returnValue = (integer) gmmktime($hours, $mins, $secs);
143  }
144 
145  $timezoneAdjustment = ($adjustToTimezone) ?
146  PHPExcel_Shared_TimeZone::getTimezoneAdjustment($timezone, $returnValue) :
147  0;
148 
149  // Return
150  return $returnValue + $timezoneAdjustment;
151  } // function ExcelToPHP()
+ Here is the caller graph for this function:

◆ ExcelToPHPObject()

static PHPExcel_Shared_Date::ExcelToPHPObject (   $dateValue = 0)
static

Convert a date from Excel to a PHP Date/Time object.

Parameters
integer$dateValueExcel date/time value
Returns
DateTime PHP date/time object

Definition at line 160 of file Date.php.

References $time.

Referenced by PHPExcel_Calculation_DateTime\_adjustDateByMonths(), PHPExcel_Calculation_Financial\_coupFirstPeriodDate(), PHPExcel_Style_NumberFormat\_formatAsDate(), PHPExcel_Calculation_DateTime\DATE(), PHPExcel_Calculation_DateTime\DATEDIF(), PHPExcel_Calculation_DateTime\DATENOW(), PHPExcel_Calculation_DateTime\DAYOFMONTH(), PHPExcel_Calculation_DateTime\DAYOFWEEK(), PHPExcel_Calculation_DateTime\DAYS360(), PHPExcel_Calculation_DateTime\MONTHOFYEAR(), PHPExcel_Calculation_DateTime\WEEKOFYEAR(), PHPExcel_Calculation_DateTime\WORKDAY(), and PHPExcel_Calculation_DateTime\YEAR().

160  {
161  $dateTime = self::ExcelToPHP($dateValue);
162  $days = floor($dateTime / 86400);
163  $time = round((($dateTime / 86400) - $days) * 86400);
164  $hours = round($time / 3600);
165  $minutes = round($time / 60) - ($hours * 60);
166  $seconds = round($time) - ($hours * 3600) - ($minutes * 60);
167 
168  $dateObj = date_create('1-Jan-1970+'.$days.' days');
169  $dateObj->setTime($hours,$minutes,$seconds);
170 
171  return $dateObj;
172  } // function ExcelToPHPObject()
$time
Definition: cron.php:21
+ Here is the caller graph for this function:

◆ FormattedPHPToExcel()

static PHPExcel_Shared_Date::FormattedPHPToExcel (   $year,
  $month,
  $day,
  $hours = 0,
  $minutes = 0,
  $seconds = 0 
)
static

FormattedPHPToExcel.

Parameters
long$year
long$month
long$day
long$hours
long$minutes
long$seconds
Returns
long Excel date/time value

Definition at line 215 of file Date.php.

Referenced by PHPExcel_Calculation_DateTime\DATE(), PHPExcel_Calculation_DateTime\DATEVALUE(), PHPExcel_Reader_OOCalc\loadIntoExisting(), PHPExcel_Calculation_DateTime\TIME(), and PHPExcel_Calculation_DateTime\TIMEVALUE().

215  {
216  if (self::$_excelBaseDate == self::CALENDAR_WINDOWS_1900) {
217  //
218  // Fudge factor for the erroneous fact that the year 1900 is treated as a Leap Year in MS Excel
219  // This affects every date following 28th February 1900
220  //
221  $excel1900isLeapYear = TRUE;
222  if (($year == 1900) && ($month <= 2)) { $excel1900isLeapYear = FALSE; }
223  $my_excelBaseDate = 2415020;
224  } else {
225  $my_excelBaseDate = 2416481;
226  $excel1900isLeapYear = FALSE;
227  }
228 
229  // Julian base date Adjustment
230  if ($month > 2) {
231  $month -= 3;
232  } else {
233  $month += 9;
234  --$year;
235  }
236 
237  // Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0)
238  $century = substr($year,0,2);
239  $decade = substr($year,2,2);
240  $excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $my_excelBaseDate + $excel1900isLeapYear;
241 
242  $excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;
243 
244  return (float) $excelDate + $excelTime;
245  } // function FormattedPHPToExcel()
+ Here is the caller graph for this function:

◆ getExcelCalendar()

static PHPExcel_Shared_Date::getExcelCalendar ( )
static

Return the Excel calendar (Windows 1900 or Mac 1904)

Returns
integer Excel base date (1900 or 1904)

Definition at line 106 of file Date.php.

Referenced by PHPExcel_Writer_Excel2007_Workbook\_writeWorkbookPr(), PHPExcel_Calculation_DateTime\DATE(), and PHPExcel_Calculation_DateTime\TIME().

106  {
107  return self::$_excelBaseDate;
108  } // function getExcelCalendar()
+ Here is the caller graph for this function:

◆ isDateTime()

static PHPExcel_Shared_Date::isDateTime ( PHPExcel_Cell  $pCell)
static

Is a given cell a date/time?

Parameters
PHPExcel_Cell$pCell
Returns
boolean

Definition at line 254 of file Date.php.

References PHPExcel_Cell\getCoordinate(), and PHPExcel_Cell\getWorksheet().

254  {
255  return self::isDateTimeFormat(
256  $pCell->getWorksheet()->getStyle(
257  $pCell->getCoordinate()
258  )->getNumberFormat()
259  );
260  } // function isDateTime()
getCoordinate()
Get cell coordinate.
Definition: Cell.php:171
getWorksheet()
Get parent worksheet.
Definition: Cell.php:488
+ Here is the call graph for this function:

◆ isDateTimeFormat()

static PHPExcel_Shared_Date::isDateTimeFormat ( PHPExcel_Style_NumberFormat  $pFormat)
static

Is a given number format a date/time?

Parameters
PHPExcel_Style_NumberFormat$pFormat
Returns
boolean

Definition at line 269 of file Date.php.

References PHPExcel_Style_NumberFormat\getFormatCode().

269  {
270  return self::isDateTimeFormatCode($pFormat->getFormatCode());
271  } // function isDateTimeFormat()
getFormatCode()
Get Format Code.
+ Here is the call graph for this function:

◆ isDateTimeFormatCode()

static PHPExcel_Shared_Date::isDateTimeFormatCode (   $pFormatCode = '')
static

Is a given number format code a date/time?

Parameters
string$pFormatCode
Returns
boolean

Definition at line 282 of file Date.php.

References PHPExcel_Style_NumberFormat\FORMAT_DATE_DATETIME, PHPExcel_Style_NumberFormat\FORMAT_DATE_DDMMYYYY, PHPExcel_Style_NumberFormat\FORMAT_DATE_DMMINUS, PHPExcel_Style_NumberFormat\FORMAT_DATE_DMYMINUS, PHPExcel_Style_NumberFormat\FORMAT_DATE_DMYSLASH, PHPExcel_Style_NumberFormat\FORMAT_DATE_MYMINUS, PHPExcel_Style_NumberFormat\FORMAT_DATE_TIME1, PHPExcel_Style_NumberFormat\FORMAT_DATE_TIME2, PHPExcel_Style_NumberFormat\FORMAT_DATE_TIME3, PHPExcel_Style_NumberFormat\FORMAT_DATE_TIME4, PHPExcel_Style_NumberFormat\FORMAT_DATE_TIME5, PHPExcel_Style_NumberFormat\FORMAT_DATE_TIME6, PHPExcel_Style_NumberFormat\FORMAT_DATE_TIME7, PHPExcel_Style_NumberFormat\FORMAT_DATE_TIME8, PHPExcel_Style_NumberFormat\FORMAT_DATE_XLSX14, PHPExcel_Style_NumberFormat\FORMAT_DATE_XLSX15, PHPExcel_Style_NumberFormat\FORMAT_DATE_XLSX16, PHPExcel_Style_NumberFormat\FORMAT_DATE_XLSX17, PHPExcel_Style_NumberFormat\FORMAT_DATE_XLSX22, PHPExcel_Style_NumberFormat\FORMAT_DATE_YYYYMMDD, PHPExcel_Style_NumberFormat\FORMAT_DATE_YYYYMMDD2, PHPExcel_Style_NumberFormat\FORMAT_DATE_YYYYMMDDSLASH, and PHPExcel_Style_NumberFormat\FORMAT_GENERAL.

Referenced by PHPExcel_Reader_Gnumeric\loadIntoExisting(), and PHPExcel_Calculation_TextData\TEXTFORMAT().

282  {
283  if (strtolower($pFormatCode) === strtolower(PHPExcel_Style_NumberFormat::FORMAT_GENERAL))
284  // "General" contains an epoch letter 'e', so we trap for it explicitly here (case-insensitive check)
285  return FALSE;
286  if (preg_match('/[0#]E[+-]0/i', $pFormatCode))
287  // Scientific format
288  return FALSE;
289  // Switch on formatcode
290  switch ($pFormatCode) {
291  // Explicitly defined date formats
314  return TRUE;
315  }
316 
317  // Typically number, currency or accounting (or occasionally fraction) formats
318  if ((substr($pFormatCode,0,1) == '_') || (substr($pFormatCode,0,2) == '0 ')) {
319  return FALSE;
320  }
321  // Try checking for any of the date formatting characters that don't appear within square braces
322  if (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$pFormatCode)) {
323  // We might also have a format mask containing quoted strings...
324  // we don't want to test for any of our characters within the quoted blocks
325  if (strpos($pFormatCode,'"') !== FALSE) {
326  $segMatcher = FALSE;
327  foreach(explode('"',$pFormatCode) as $subVal) {
328  // Only test in alternate array entries (the non-quoted blocks)
329  if (($segMatcher = !$segMatcher) &&
330  (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$subVal))) {
331  return TRUE;
332  }
333  }
334  return FALSE;
335  }
336  return TRUE;
337  }
338 
339  // No date...
340  return FALSE;
341  } // function isDateTimeFormatCode()
+ Here is the caller graph for this function:

◆ monthStringToNumber()

static PHPExcel_Shared_Date::monthStringToNumber (   $month)
static

Definition at line 374 of file Date.php.

Referenced by PHPExcel_Calculation_DateTime\DATE().

374  {
375  $monthIndex = 1;
376  foreach(self::$_monthNames as $shortMonthName => $longMonthName) {
377  if (($month === $longMonthName) || ($month === $shortMonthName)) {
378  return $monthIndex;
379  }
380  ++$monthIndex;
381  }
382  return $month;
383  }
+ Here is the caller graph for this function:

◆ PHPToExcel()

static PHPExcel_Shared_Date::PHPToExcel (   $dateValue = 0,
  $adjustToTimezone = FALSE,
  $timezone = NULL 
)
static

Convert a date from PHP to Excel.

Parameters
mixed$dateValuePHP serialized date/time or date object
boolean$adjustToTimezoneFlag indicating whether $dateValue should be treated as a UST timestamp, or adjusted to UST
string$timezoneThe timezone for finding the adjustment from UST
Returns
mixed Excel date/time value or boolean FALSE on failure

Definition at line 185 of file Date.php.

References date.

Referenced by PHPExcel_Calculation_Financial\_coupFirstPeriodDate(), PHPExcel_Worksheet_AutoFilter\_dynamicFilterDateRange(), PHPExcel_Calculation_DateTime\_getDateValue(), PHPExcel_Calculation_DateTime\DATENOW(), PHPExcel_Calculation_DateTime\DATETIMENOW(), PHPExcel_Calculation_DateTime\EDATE(), PHPExcel_Calculation_DateTime\EOMONTH(), PHPExcel_Reader_Excel2003XML\loadIntoExisting(), and PHPExcel_Reader_OOCalc\loadIntoExisting().

185  {
186  $saveTimeZone = date_default_timezone_get();
187  date_default_timezone_set('UTC');
188  $retValue = FALSE;
189  if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
190  $retValue = self::FormattedPHPToExcel( $dateValue->format('Y'), $dateValue->format('m'), $dateValue->format('d'),
191  $dateValue->format('H'), $dateValue->format('i'), $dateValue->format('s')
192  );
193  } elseif (is_numeric($dateValue)) {
194  $retValue = self::FormattedPHPToExcel( date('Y',$dateValue), date('m',$dateValue), date('d',$dateValue),
195  date('H',$dateValue), date('i',$dateValue), date('s',$dateValue)
196  );
197  }
198  date_default_timezone_set($saveTimeZone);
199 
200  return $retValue;
201  } // function PHPToExcel()
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
+ Here is the caller graph for this function:

◆ setExcelCalendar()

static PHPExcel_Shared_Date::setExcelCalendar (   $baseDate)
static

Set the Excel calendar (Windows 1900 or Mac 1904)

Parameters
integer$baseDateExcel base date (1900 or 1904)
Returns
boolean Success or failure

Definition at line 91 of file Date.php.

Referenced by PHPExcel_Reader_Excel5\_readDateMode(), PHPExcel_Reader_Excel2007\load(), DateTimeTest\testDATEwith1904Calendar(), and DateTimeTest\testDATEwith1904CalendarError().

91  {
92  if (($baseDate == self::CALENDAR_WINDOWS_1900) ||
93  ($baseDate == self::CALENDAR_MAC_1904)) {
94  self::$_excelBaseDate = $baseDate;
95  return TRUE;
96  }
97  return FALSE;
98  } // function setExcelCalendar()
+ Here is the caller graph for this function:

◆ stringToExcel()

static PHPExcel_Shared_Date::stringToExcel (   $dateValue = '')
static

Convert a date/time string to Excel time.

Parameters
string$dateValueExamples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'
Returns
float|FALSE Excel date/time serial value

Definition at line 350 of file Date.php.

References PHPExcel_Calculation_DateTime\DATEVALUE(), PHPExcel_Calculation_DateTime\TIMEVALUE(), and PHPExcel_Calculation_Functions\VALUE().

Referenced by PHPExcel_Cell_AdvancedValueBinder\bindValue(), and ilExcel\prepareDateValue().

350  {
351  if (strlen($dateValue) < 2)
352  return FALSE;
353  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))
354  return FALSE;
355 
356  $dateValueNew = PHPExcel_Calculation_DateTime::DATEVALUE($dateValue);
357 
358  if ($dateValueNew === PHPExcel_Calculation_Functions::VALUE()) {
359  return FALSE;
360  } else {
361  if (strpos($dateValue, ':') !== FALSE) {
362  $timeValue = PHPExcel_Calculation_DateTime::TIMEVALUE($dateValue);
363  if ($timeValue === PHPExcel_Calculation_Functions::VALUE()) {
364  return FALSE;
365  }
366  $dateValueNew += $timeValue;
367  }
368  return $dateValueNew;
369  }
370 
371 
372  }
static DATEVALUE($dateValue=1)
Definition: DateTime.php:481
static TIMEVALUE($timeValue)
Definition: DateTime.php:583
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $_excelBaseDate

PHPExcel_Shared_Date::$_excelBaseDate = self::CALENDAR_WINDOWS_1900
staticprotected

Definition at line 83 of file Date.php.

◆ $_monthNames

PHPExcel_Shared_Date::$_monthNames
static
Initial value:
= array( 'Jan' => 'January',
'Feb' => 'February',
'Mar' => 'March',
'Apr' => 'April',
'May' => 'May',
'Jun' => 'June',
'Jul' => 'July',
'Aug' => 'August',
'Sep' => 'September',
'Oct' => 'October',
'Nov' => 'November',
'Dec' => 'December',
)

Definition at line 50 of file Date.php.

◆ $_numberSuffixes

PHPExcel_Shared_Date::$_numberSuffixes
static
Initial value:
= array( 'st',
'nd',
'rd',
'th',
)

Definition at line 71 of file Date.php.

◆ $possibleDateFormatCharacters

PHPExcel_Shared_Date::$possibleDateFormatCharacters = 'eymdHs'
staticprivate

Definition at line 274 of file Date.php.

◆ CALENDAR_MAC_1904

◆ CALENDAR_WINDOWS_1900


The documentation for this class was generated from the following file: