| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * PHPExcel | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-03-03 21:16:09 +00:00
										 |  |  |  * Copyright (c) 2006 - 2012 PHPExcel | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							|  |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License along with this library; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category   PHPExcel | 
					
						
							|  |  |  |  * @package	PHPExcel_Shared | 
					
						
							| 
									
										
										
										
											2012-03-03 21:16:09 +00:00
										 |  |  |  * @copyright  Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  |  * @license	http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL | 
					
						
							|  |  |  |  * @version	##VERSION##, ##DATE##
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * PHPExcel_Shared_Date | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category   PHPExcel | 
					
						
							|  |  |  |  * @package	PHPExcel_Shared | 
					
						
							| 
									
										
										
										
											2012-03-03 21:16:09 +00:00
										 |  |  |  * @copyright  Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | class PHPExcel_Shared_Date | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/** constants */ | 
					
						
							|  |  |  | 	const CALENDAR_WINDOWS_1900 = 1900;		//	Base date of 1st Jan 1900 = 1.0
 | 
					
						
							|  |  |  | 	const CALENDAR_MAC_1904 = 1904;			//	Base date of 2nd Jan 1904 = 1.0
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-11 19:24:20 +00:00
										 |  |  | 	/* | 
					
						
							|  |  |  | 	 * Names of the months of the year, indexed by shortname | 
					
						
							|  |  |  | 	 * Planned usage for locale settings | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @public | 
					
						
							|  |  |  | 	 * @var	string[] | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-01-29 14:25:25 +00:00
										 |  |  | 	public static $_monthNames = 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' | 
					
						
							|  |  |  | 									  ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-11 19:24:20 +00:00
										 |  |  | 	/* | 
					
						
							|  |  |  | 	 * Base calendar year to use for calculations | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @private | 
					
						
							|  |  |  | 	 * @var	int | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-11-03 21:52:55 +00:00
										 |  |  | 	protected static $_excelBaseDate	= self::CALENDAR_WINDOWS_1900; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Set the Excel calendar (Windows 1900 or Mac 1904) | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 	 * @param	 integer	$baseDate			Excel base date (1900 or 1904) | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 	 * @return	 boolean						Success or failure | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public static function setExcelCalendar($baseDate) { | 
					
						
							|  |  |  | 		if (($baseDate == self::CALENDAR_WINDOWS_1900) || | 
					
						
							|  |  |  | 			($baseDate == self::CALENDAR_MAC_1904)) { | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 			self::$_excelBaseDate = $baseDate; | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 			return TRUE; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 		return FALSE; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 	}	//	function setExcelCalendar()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Return the Excel calendar (Windows 1900 or Mac 1904) | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 	 * @return	 integer	Excel base date (1900 or 1904) | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public static function getExcelCalendar() { | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 		return self::$_excelBaseDate; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 	}	//	function getExcelCalendar()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 *	Convert a date from Excel to PHP | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 *	@param		long		$dateValue			Excel date/time value | 
					
						
							|  |  |  | 	 *	@param		boolean		$adjustToTimezone	Flag indicating whether $dateValue should be treated as | 
					
						
							|  |  |  | 	 *													a UST timestamp, or adjusted to UST | 
					
						
							|  |  |  | 	 *	@param		string	 	$timezone			The timezone for finding the adjustment from UST | 
					
						
							| 
									
										
										
										
											2012-11-03 21:52:55 +00:00
										 |  |  | 	 *	@return		long		PHP serialized date/time | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public static function ExcelToPHP($dateValue = 0, $adjustToTimezone = FALSE, $timezone = NULL) { | 
					
						
							|  |  |  | 		if (self::$_excelBaseDate == self::CALENDAR_WINDOWS_1900) { | 
					
						
							|  |  |  | 			$my_excelBaseDate = 25569; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 			//	Adjust for the spurious 29-Feb-1900 (Day 60)
 | 
					
						
							|  |  |  | 			if ($dateValue < 60) { | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 				--$my_excelBaseDate; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 			$my_excelBaseDate = 24107; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Perform conversion
 | 
					
						
							|  |  |  | 		if ($dateValue >= 1) { | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 			$utcDays = $dateValue - $my_excelBaseDate; | 
					
						
							| 
									
										
										
										
											2011-04-09 18:16:08 +00:00
										 |  |  | 			$returnValue = round($utcDays * 86400); | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 			if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) { | 
					
						
							|  |  |  | 				$returnValue = (integer) $returnValue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$hours = round($dateValue * 24); | 
					
						
							| 
									
										
										
										
											2011-04-09 18:16:08 +00:00
										 |  |  | 			$mins = round($dateValue * 1440) - round($hours * 60); | 
					
						
							|  |  |  | 			$secs = round($dateValue * 86400) - round($hours * 3600) - round($mins * 60); | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 			$returnValue = (integer) gmmktime($hours, $mins, $secs); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-03 21:52:55 +00:00
										 |  |  | 		$timezoneAdjustment = ($adjustToTimezone) ? | 
					
						
							|  |  |  | 		    PHPExcel_Shared_TimeZone::getTimezoneAdjustment($timezone, $returnValue) : | 
					
						
							|  |  |  | 		    0; | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 		// Return
 | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 		return $returnValue + $timezoneAdjustment; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 	}	//	function ExcelToPHP()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Convert a date from Excel to a PHP Date/Time object | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2012-11-03 21:52:55 +00:00
										 |  |  | 	 * @param	integer		$dateValue		Excel date/time value | 
					
						
							|  |  |  | 	 * @return	integer						PHP date/time object | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public static function ExcelToPHPObject($dateValue = 0) { | 
					
						
							|  |  |  | 		$dateTime = self::ExcelToPHP($dateValue); | 
					
						
							|  |  |  | 		$days = floor($dateTime / 86400); | 
					
						
							|  |  |  | 		$time = round((($dateTime / 86400) - $days) * 86400); | 
					
						
							|  |  |  | 		$hours = round($time / 3600); | 
					
						
							|  |  |  | 		$minutes = round($time / 60) - ($hours * 60); | 
					
						
							|  |  |  | 		$seconds = round($time) - ($hours * 3600) - ($minutes * 60); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$dateObj = date_create('1-Jan-1970+'.$days.' days'); | 
					
						
							|  |  |  | 		$dateObj->setTime($hours,$minutes,$seconds); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $dateObj; | 
					
						
							|  |  |  | 	}	//	function ExcelToPHPObject()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2012-11-03 21:52:55 +00:00
										 |  |  | 	 *	Convert a date from PHP to Excel | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2012-11-03 21:52:55 +00:00
										 |  |  | 	 *	@param	mixed		$dateValue			PHP serialized date/time or date object | 
					
						
							|  |  |  | 	 *	@param	boolean		$adjustToTimezone	Flag indicating whether $dateValue should be treated as | 
					
						
							|  |  |  | 	 *													a UST timestamp, or adjusted to UST | 
					
						
							|  |  |  | 	 *	@param	string	 	$timezone			The timezone for finding the adjustment from UST | 
					
						
							|  |  |  | 	 *	@return	mixed		Excel date/time value | 
					
						
							|  |  |  | 	 *							or boolean FALSE on failure | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 	public static function PHPToExcel($dateValue = 0, $adjustToTimezone = FALSE, $timezone = NULL) { | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 		$saveTimeZone = date_default_timezone_get(); | 
					
						
							|  |  |  | 		date_default_timezone_set('UTC'); | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 		$retValue = FALSE; | 
					
						
							| 
									
										
										
										
											2012-10-29 23:48:29 +00:00
										 |  |  | 		if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) { | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 			$retValue = self::FormattedPHPToExcel( $dateValue->format('Y'), $dateValue->format('m'), $dateValue->format('d'), | 
					
						
							|  |  |  | 												   $dateValue->format('H'), $dateValue->format('i'), $dateValue->format('s') | 
					
						
							|  |  |  | 												 ); | 
					
						
							|  |  |  | 		} elseif (is_numeric($dateValue)) { | 
					
						
							|  |  |  | 			$retValue = self::FormattedPHPToExcel( date('Y',$dateValue), date('m',$dateValue), date('d',$dateValue), | 
					
						
							|  |  |  | 												   date('H',$dateValue), date('i',$dateValue), date('s',$dateValue) | 
					
						
							|  |  |  | 												 ); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		date_default_timezone_set($saveTimeZone); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $retValue; | 
					
						
							|  |  |  | 	}	//	function PHPToExcel()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * FormattedPHPToExcel | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	long	$year | 
					
						
							|  |  |  | 	 * @param	long	$month | 
					
						
							|  |  |  | 	 * @param	long	$day | 
					
						
							|  |  |  | 	 * @param	long	$hours | 
					
						
							|  |  |  | 	 * @param	long	$minutes | 
					
						
							|  |  |  | 	 * @param	long	$seconds | 
					
						
							|  |  |  | 	 * @return  long				Excel date/time value | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public static function FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0) { | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 		if (self::$_excelBaseDate == self::CALENDAR_WINDOWS_1900) { | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 			//
 | 
					
						
							|  |  |  | 			//	Fudge factor for the erroneous fact that the year 1900 is treated as a Leap Year in MS Excel
 | 
					
						
							|  |  |  | 			//	This affects every date following 28th February 1900
 | 
					
						
							|  |  |  | 			//
 | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 			$excel1900isLeapYear = TRUE; | 
					
						
							|  |  |  | 			if (($year == 1900) && ($month <= 2)) { $excel1900isLeapYear = FALSE; } | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 			$my_excelBaseDate = 2415020; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 			$my_excelBaseDate = 2416481; | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 			$excel1900isLeapYear = FALSE; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//	Julian base date Adjustment
 | 
					
						
							|  |  |  | 		if ($month > 2) { | 
					
						
							| 
									
										
										
										
											2011-12-03 10:02:24 +00:00
										 |  |  | 			$month -= 3; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2011-12-03 10:02:24 +00:00
										 |  |  | 			$month += 9; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 			--$year; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//	Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0)
 | 
					
						
							|  |  |  | 		$century = substr($year,0,2); | 
					
						
							|  |  |  | 		$decade = substr($year,2,2); | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 		$excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $my_excelBaseDate + $excel1900isLeapYear; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return (float) $excelDate + $excelTime; | 
					
						
							|  |  |  | 	}	//	function FormattedPHPToExcel()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Is a given cell a date/time? | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	 PHPExcel_Cell	$pCell | 
					
						
							|  |  |  | 	 * @return	 boolean | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public static function isDateTime(PHPExcel_Cell $pCell) { | 
					
						
							| 
									
										
										
										
											2012-08-01 16:25:10 +00:00
										 |  |  | 		return self::isDateTimeFormat( | 
					
						
							|  |  |  | 			$pCell->getParent()->getStyle( | 
					
						
							|  |  |  | 				$pCell->getCoordinate() | 
					
						
							|  |  |  | 			)->getNumberFormat() | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 	}	//	function isDateTime()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Is a given number format a date/time? | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	 PHPExcel_Style_NumberFormat	$pFormat | 
					
						
							|  |  |  | 	 * @return	 boolean | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public static function isDateTimeFormat(PHPExcel_Style_NumberFormat $pFormat) { | 
					
						
							|  |  |  | 		return self::isDateTimeFormatCode($pFormat->getFormatCode()); | 
					
						
							|  |  |  | 	}	//	function isDateTimeFormat()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 19:55:27 +00:00
										 |  |  | 	private static	$possibleDateFormatCharacters = 'eymdHs'; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Is a given number format code a date/time? | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	 string	$pFormatCode | 
					
						
							|  |  |  | 	 * @return	 boolean | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public static function isDateTimeFormatCode($pFormatCode = '') { | 
					
						
							|  |  |  | 		// Switch on formatcode
 | 
					
						
							|  |  |  | 		switch ($pFormatCode) { | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 			//	General contains an epoch letter 'e', so we trap for it explicitly here
 | 
					
						
							| 
									
										
										
										
											2012-07-24 06:39:36 +00:00
										 |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_GENERAL: | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 				return FALSE; | 
					
						
							|  |  |  | 			//	Explicitly defined date formats
 | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYMINUS: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMMINUS: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_MYMINUS: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME1: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME2: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME5: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME6: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME7: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME8: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17: | 
					
						
							|  |  |  | 			case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22: | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 				return TRUE; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-28 15:53:49 +00:00
										 |  |  | 		//	Typically number, currency or accounting (or occasionally fraction) formats
 | 
					
						
							|  |  |  | 		if ((substr($pFormatCode,0,1) == '_') || (substr($pFormatCode,0,2) == '0 ')) { | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 			return FALSE; | 
					
						
							| 
									
										
										
										
											2010-09-28 15:53:49 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 		// Try checking for any of the date formatting characters that don't appear within square braces
 | 
					
						
							|  |  |  | 		if (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$pFormatCode)) { | 
					
						
							| 
									
										
										
										
											2011-02-10 12:26:50 +00:00
										 |  |  | 			//	We might also have a format mask containing quoted strings...
 | 
					
						
							|  |  |  | 			//		we don't want to test for any of our characters within the quoted blocks
 | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 			if (strpos($pFormatCode,'"') !== FALSE) { | 
					
						
							| 
									
										
										
										
											2012-11-03 21:52:55 +00:00
										 |  |  | 				$segMatcher = FALSE; | 
					
						
							| 
									
										
										
										
											2011-02-10 12:26:50 +00:00
										 |  |  | 				foreach(explode('"',$pFormatCode) as $subVal) { | 
					
						
							|  |  |  | 					//	Only test in alternate array entries (the non-quoted blocks)
 | 
					
						
							| 
									
										
										
										
											2012-11-03 21:52:55 +00:00
										 |  |  | 					if (($segMatcher = !$segMatcher) && | 
					
						
							|  |  |  | 						(preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$subVal))) { | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 						return TRUE; | 
					
						
							| 
									
										
										
										
											2011-02-10 12:26:50 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 				return FALSE; | 
					
						
							| 
									
										
										
										
											2011-02-10 12:26:50 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 			return TRUE; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// No date...
 | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 		return FALSE; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 	}	//	function isDateTimeFormatCode()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Convert a date/time string to Excel time | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	string	$dateValue		Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10' | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 	 * @return	float|FALSE		Excel date/time serial value | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public static function stringToExcel($dateValue = '') { | 
					
						
							| 
									
										
										
										
											2010-10-13 13:16:02 +00:00
										 |  |  | 		if (strlen($dateValue) < 2) | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 			return FALSE; | 
					
						
							| 
									
										
										
										
											2011-01-29 17:05:02 +00:00
										 |  |  | 		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)) | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 			return FALSE; | 
					
						
							| 
									
										
										
										
											2010-10-13 13:16:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-03 14:28:57 +00:00
										 |  |  | 		$dateValueNew = PHPExcel_Calculation_DateTime::DATEVALUE($dateValue); | 
					
						
							| 
									
										
										
										
											2010-09-10 14:57:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ($dateValueNew === PHPExcel_Calculation_Functions::VALUE()) { | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 			return FALSE; | 
					
						
							| 
									
										
										
										
											2010-09-10 14:57:07 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 			if (strpos($dateValue, ':') !== FALSE) { | 
					
						
							| 
									
										
										
										
											2010-12-03 14:28:57 +00:00
										 |  |  | 				$timeValue = PHPExcel_Calculation_DateTime::TIMEVALUE($dateValue); | 
					
						
							| 
									
										
										
										
											2010-09-10 14:57:07 +00:00
										 |  |  | 				if ($timeValue === PHPExcel_Calculation_Functions::VALUE()) { | 
					
						
							| 
									
										
										
										
											2012-07-23 20:52:14 +00:00
										 |  |  | 					return FALSE; | 
					
						
							| 
									
										
										
										
											2010-09-10 14:57:07 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				$dateValueNew += $timeValue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return $dateValueNew; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |