Skip to content

Commit

Permalink
Merge branch 'feature/gh-7' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/PhpSpreadsheet/Shared/Date.php
  • Loading branch information
MarkBaker committed Aug 16, 2016
2 parents e87ec85 + f8c3363 commit e0a9f9e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/PhpSpreadsheet/Shared/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public static function getExcelCalendar()
/**
* Set the Default timezone to use for dates
*
* @param string|\DateTimeZone $timezone The timezone to set for all Excel datetimestamp to PHP DateTime Object conversions
* @param string|\DateTimeZone $timeZone The timezone to set for all Excel datetimestamp to PHP DateTime Object conversions
* @return boolean Success or failure
* @throws \Exception
* @return bool Success or failure
*/
Expand Down Expand Up @@ -145,7 +146,8 @@ public static function getDefaultTimezone()
/**
* Validate a timezone
*
* @param string|\DateTimeZone $timezone The timezone to validate, either as a timezone string or object
* @param string|\DateTimeZone $timeZone The timezone to validate, either as a timezone string or object
* @return \DateTimeZone The timezone as a timezone object
* @throws \Exception
* @return \DateTimeZone The timezone as a timezone object
*/
Expand All @@ -162,8 +164,8 @@ protected static function validateTimeZone($timeZone)
/**
* Convert a MS serialized datetime value from Excel to a PHP Date/Time object
*
* @param int|float $dateValue MS Excel serialized date/time value
* @param \DateTimeZone|string|null $timezone The timezone to assume for the Excel timestamp,
* @param integer|float $excelTimestamp MS Excel serialized date/time value
* @param \DateTimeZone|string|null $timeZone The timezone to assume for the Excel timestamp,
* if you don't want to treat it as a UTC value
* Use the default (UST) unless you absolutely need a conversion
* @throws \Exception
Expand Down Expand Up @@ -201,8 +203,8 @@ public static function excelToDateTimeObject($excelTimestamp = 0, $timeZone = nu
/**
* Convert a MS serialized datetime value from Excel to a unix timestamp
*
* @param int|float $dateValue MS Excel serialized date/time value
* @param \DateTimeZone|string|null $timezone The timezone to assume for the Excel timestamp,
* @param integer|float $excelTimestamp MS Excel serialized date/time value
* @param \DateTimeZone|string|null $timeZone The timezone to assume for the Excel timestamp,
* if you don't want to treat it as a UTC value
* Use the default (UST) unless you absolutely need a conversion
* @throws \Exception
Expand All @@ -217,16 +219,16 @@ public static function excelToTimestamp($excelTimestamp = 0, $timeZone = null)
/**
* Convert a date from PHP to an MS Excel serialized date/time value
*
* @param mixed $dateValue PHP serialized date/time or date object
* @return float|bool Excel date/time value
* @param mixed $dateValue Unix Timestamp or PHP DateTime object or a string
* @return float|boolean Excel date/time value
* or boolean FALSE on failure
*/
public static function PHPToExcel($dateValue = 0)
{
if ((is_object($dateValue)) && ($dateValue instanceof \DateTimeInterface)) {
return self::DateTimeToExcel($dateValue);
return self::dateTimeToExcel($dateValue);
} elseif (is_numeric($dateValue)) {
return self::TimestampToExcel($dateValue);
return self::timestampToExcel($dateValue);
} elseif (is_string($dateValue)) {
return self::stringToExcel($dateValue);
}
Expand All @@ -235,7 +237,7 @@ public static function PHPToExcel($dateValue = 0)
}

/**
* Convert a DateTime object to an MS Excel serialized date/time value
* Convert a PHP DateTime object to an MS Excel serialized date/time value
*
* @param \DateTimeInterface $dateValue PHP DateTime object
* @return float MS Excel serialized date/time value
Expand All @@ -255,16 +257,15 @@ public static function dateTimeToExcel(\DateTimeInterface $dateValue = null)
/**
* Convert a Unix timestamp to an MS Excel serialized date/time value
*
* @param \DateTimeInterface $dateValue PHP DateTime object
* @param \DateTimeInterface $dateValue Unix Timestamp
* @return float MS Excel serialized date/time value
*/
public static function timestampToExcel($dateValue = 0)
{
if (!is_numeric($dateValue)) {
return false;
}

return self::DateTimeToExcel(new \DateTime('@' . $dateValue));
return self::dateTimeToExcel(new \DateTime('@' . $dateValue));
}

/**
Expand Down

0 comments on commit e0a9f9e

Please sign in to comment.