Minor tweaks and bugfixes
This commit is contained in:
parent
7760d5ffc6
commit
d8debd0966
|
@ -238,6 +238,10 @@ class PHPExcel_Calculation_DateTime {
|
|||
* Excel Function:
|
||||
* DATE(year,month,day)
|
||||
*
|
||||
* PHPExcel is a lot more forgiving than MS Excel when passing non numeric values to this function.
|
||||
* A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted,
|
||||
* as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language.
|
||||
*
|
||||
* @access public
|
||||
* @category Date/Time Functions
|
||||
* @param integer $year The value of the year argument can include one to four digits.
|
||||
|
@ -278,6 +282,14 @@ class PHPExcel_Calculation_DateTime {
|
|||
$month = PHPExcel_Calculation_Functions::flattenSingleValue($month);
|
||||
$day = PHPExcel_Calculation_Functions::flattenSingleValue($day);
|
||||
|
||||
if (($month !== NULL) && (!is_numeric($month))) {
|
||||
$month = PHPExcel_Shared_Date::monthStringToNumber($month);
|
||||
}
|
||||
|
||||
if (($day !== NULL) && (!is_numeric($day))) {
|
||||
$day = PHPExcel_Shared_Date::dayStringToNumber($day);
|
||||
}
|
||||
|
||||
$year = ($year !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($year) : 0;
|
||||
$month = ($month !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($month) : 0;
|
||||
$day = ($day !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($day) : 0;
|
||||
|
@ -720,6 +732,10 @@ class PHPExcel_Calculation_DateTime {
|
|||
return PHPExcel_Calculation_Functions::VALUE();
|
||||
}
|
||||
|
||||
if (!is_bool($method)) {
|
||||
return PHPExcel_Calculation_Functions::VALUE();
|
||||
}
|
||||
|
||||
// Execute function
|
||||
$PHPStartDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($startDate);
|
||||
$startDay = $PHPStartDateObject->format('j');
|
||||
|
|
|
@ -58,7 +58,20 @@ class PHPExcel_Shared_Date
|
|||
'Sep' => 'September',
|
||||
'Oct' => 'October',
|
||||
'Nov' => 'November',
|
||||
'Dec' => 'December'
|
||||
'Dec' => 'December',
|
||||
);
|
||||
|
||||
/*
|
||||
* Names of the months of the year, indexed by shortname
|
||||
* Planned usage for locale settings
|
||||
*
|
||||
* @public
|
||||
* @var string[]
|
||||
*/
|
||||
public static $_numberSuffixes = array( 'st',
|
||||
'nd',
|
||||
'rd',
|
||||
'th',
|
||||
);
|
||||
|
||||
/*
|
||||
|
@ -355,4 +368,23 @@ class PHPExcel_Shared_Date
|
|||
|
||||
}
|
||||
|
||||
public static function monthStringToNumber($month) {
|
||||
$monthIndex = 1;
|
||||
foreach(self::$_monthNames as $shortMonthName => $longMonthName) {
|
||||
if (($month === $longMonthName) || ($month === $shortMonthName)) {
|
||||
return $monthIndex;
|
||||
}
|
||||
++$monthIndex;
|
||||
}
|
||||
return $month;
|
||||
}
|
||||
|
||||
public static function dayStringToNumber($day) {
|
||||
$strippedDayValue = (str_replace(self::$_numberSuffixes,'',$day));
|
||||
if (is_numeric($strippedDayValue)) {
|
||||
return $strippedDayValue;
|
||||
}
|
||||
return $day;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -72,8 +72,8 @@
|
|||
2010, 0, -1, 40146
|
||||
2010, 5, 31, 40329
|
||||
2010, 1, '21st', 40199 // MS Excel will fail with a #VALUE return, but PHPExcel can parse this date
|
||||
2010, "March",'21st', 40168 // MS Excel will fail with a #VALUE return, but PHPExcel can parse this date
|
||||
2010, "March",21, 40168 // MS Excel will fail with a #VALUE return, but PHPExcel can parse this date
|
||||
2010, "March",'21st', 40258 // MS Excel will fail with a #VALUE return, but PHPExcel can parse this date
|
||||
2010, "March",21, 40258 // MS Excel will fail with a #VALUE return, but PHPExcel can parse this date
|
||||
"ABC", 1, 21, "#VALUE!"
|
||||
2010, "DEF", 21, "#VALUE!"
|
||||
2010, 3, "GHI", "#VALUE!"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"ABC", "2007-1-10", FALSE, "#VALUE!"
|
||||
"2007-1-1", "DEF", TRUE, "#VALUE!"
|
||||
"2007-1-1", "2007-1-10", "XYZ", "#VALUE!"
|
||||
"2007-1-10", "2007-1-1", "Y", "#NUM!"
|
||||
"2007-1-10", "2007-1-1", "Y", "#VALUE!"
|
||||
"2007-1-1", "2007-1-10", FALSE, 9
|
||||
"2007-1-1", "2007-1-10", TRUE, 9
|
||||
"2007-1-1", "2007-12-31", FALSE, 360
|
||||
|
|
Loading…
Reference in New Issue